List of usage examples for java.lang Thread setDaemon
public final void setDaemon(boolean on)
From source file:net.pandoragames.far.ui.swing.menu.FileMenu.java
private void init(final Localizer localizer, final ComponentRepository componentRepository) { // Import/*from w w w .j ava 2s . c o m*/ JMenuItem importMenu = new JMenuItem(localizer.localize("label.import")); importMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(config.getFileListExportDirectory()); fileChooser.setDialogTitle(localizer.localize("label.select-import-file")); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = fileChooser.showOpenDialog(FileMenu.this); if (returnVal == JFileChooser.APPROVE_OPTION) { Runnable fileImporter = new ImportAction(fileChooser.getSelectedFile(), localizer, componentRepository.getOperationCallBackListener(), config.isWindows()); Thread thread = new Thread(fileImporter); thread.setDaemon(true); thread.start(); } } }); this.add(importMenu); // Export export = new JMenuItem(localizer.localize("label.export")); export.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ExportFileListDialog dialog = new ExportFileListDialog(mainFrame, tableModel, config); dialog.pack(); dialog.setVisible(true); } }); this.add(export); // seperator this.addSeparator(); // Edit edit = new JMenuItem(localizer.localize("label.edit")); edit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileEditor editor = new FileEditor(mainFrame, tableModel.getSelectedRows().get(0), config); editor.pack(); editor.setVisible(true); } }); this.add(edit); // View JMenuItem view = new JMenuItem(viewAction); this.add(view); // Preview JMenuItem preview = new JMenuItem(previewAction); this.add(preview); // Info info = new JMenuItem(localizer.localize("label.info")); info.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { InfoView infoView = new InfoView(mainFrame, tableModel.getSelectedRows().get(0), config, repository); infoView.pack(); infoView.setVisible(true); } }); this.add(info); // seperator this.addSeparator(); // copy copy = new JMenuItem(localizer.localize("menu.copy")); copy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.copyDialog(tableModel, findForm, errorSink, config, mainFrame); } }); this.add(copy); // tree copy treeCopy = new JMenuItem(localizer.localize("menu.treeCopy")); treeCopy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.treeCopyDialog(tableModel, findForm, errorSink, config, mainFrame); } }); this.add(treeCopy); // move move = new JMenuItem(localizer.localize("menu.move")); move.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.moveDialog(tableModel, findForm, errorSink, config, mainFrame); } }); this.add(move); // delete delete = new JMenuItem(localizer.localize("menu.delete")); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.deleteDialog(tableModel, findForm.getBaseDirectory(), errorSink, config, mainFrame); } }); this.add(delete); // rename rename = new JMenuItem(localizer.localize("menu.rename-dialog")); rename.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowIndex = tableModel.getRowIndex(tableModel.getSelectedRows().get(0)); FileOperationDialog.renameDialog(rowIndex, tableModel, findForm, errorSink, config, mainFrame); } }); this.add(rename); }
From source file:com.brsanthu.googleanalytics.GoogleAnalytics.java
public Thread newThread(Runnable r) { Thread thread = new Thread(Thread.currentThread().getThreadGroup(), r, MessageFormat.format(threadNameFormat, threadNumber.getAndIncrement()), 0); thread.setDaemon(true); thread.setPriority(Thread.MIN_PRIORITY); return thread; }
From source file:com.betfair.cougar.client.socket.ExecutionVenueNioClient.java
/** * Starts the client// w w w.j av a2 s .co m * * @return a Future<Boolean> that is true once the connection is established */ public synchronized FutureTask<Boolean> start() { this.sessionFactory.start(); if (rpcTimeoutChecker != null) { rpcTimeoutChecker.getThread().start(); } final FutureTask<Boolean> futureTask = new FutureTask<Boolean>(new Callable<Boolean>() { @Override public Boolean call() throws Exception { while (!ExecutionVenueNioClient.this.sessionFactory.isConnected()) { Thread.sleep(50); } return true; } }); final Thread thread = new Thread(futureTask); thread.setDaemon(true); thread.start(); return futureTask; }
From source file:com.betfair.cougar.client.socket.ExecutionVenueNioClient.java
/** * Stops the client./*from ww w .j a va 2s . c om*/ */ public synchronized FutureTask<Boolean> stop() { this.sessionFactory.stop(); if (rpcTimeoutChecker != null) { rpcTimeoutChecker.stop(); } final FutureTask<Boolean> futureTask = new FutureTask<Boolean>(new Callable<Boolean>() { @Override public Boolean call() throws Exception { while (ExecutionVenueNioClient.this.sessionFactory.isConnected()) { Thread.sleep(50); } return true; } }); final Thread thread = new Thread(futureTask); thread.setDaemon(true); thread.start(); return futureTask; }
From source file:org.sakaiproject.adminsiteperms.service.SitePermsService.java
/** * Set permissions (perms) in a set of site types (types) for a set of roles (roles) * //w w w . j a va2s .c om * @param perms a list of permission keys * @param types a list of site types (course/project/workspace/etc.) * @param roles a list of site roles * @param add if true then add the permissions, if false then remove them */ public void setSiteRolePerms(final String[] perms, final String[] types, final String[] roles, final boolean add) { if (!securityService.isSuperUser()) { throw new SecurityException("setSiteRolePerms is only usable by super users"); } if (isLockedForUpdates()) { throw new IllegalStateException("Cannot start new perms update, one is already in progress"); } // get the configurable values pauseTimeMS = serverConfigurationService.getConfig("site.adminperms.pause.ms", pauseTimeMS); int maxUpdateTimeS = serverConfigurationService.getConfig("site.adminperms.maxrun.secs", DEFAULT_MAX_UPDATE_TIME_SECS); maxUpdateTimeMS = 1000l * maxUpdateTimeS; // covert to milliseconds sitesUntilPause = serverConfigurationService.getConfig("site.adminperms.sitesuntilpause", sitesUntilPause); // get the current state final User currentUser = userDirectoryService.getCurrentUser(); final Session currentSession = sessionManager.getCurrentSession(); // run this in a new thread Runnable backgroundRunner = new Runnable() { public void run() { try { initiateSitePermsThread(currentUser, currentSession, perms, types, roles, add); } catch (IllegalStateException e) { throw e; // rethrow this back out } catch (Exception e) { log.error("SitePerms background perms runner thread died: " + e, e); } } }; Thread bgThread = new Thread(backgroundRunner); bgThread.setDaemon(true); // important, otherwise JVM cannot exit bgThread.start(); }
From source file:net.chat.utils.Cache.java
public Cache(long timeToLiveInSeconds, final long timerIntervalInSeconds, int maxItems) { this.timeToLiveInMillis = timeToLiveInSeconds * 1000; cacheMap = new LRUMap(maxItems); if (timeToLiveInMillis > 0 && timerIntervalInSeconds > 0) { Thread t = new Thread(new Runnable() { public void run() { while (true) { try { Thread.sleep(timerIntervalInSeconds * 1000); } catch (InterruptedException ex) { }//from w ww. jav a2 s . co m cleanup(); } } }); t.setDaemon(true); t.start(); } }
From source file:com.opengamma.livedata.client.CogdaLiveDataClient.java
@Override public void start() { if (_socket != null) { throw new IllegalStateException("Socket is currently established."); }//from w w w. ja v a2s . co m InetAddress serverAddress = null; try { serverAddress = InetAddress.getByName(getServerName()); } catch (UnknownHostException ex) { s_logger.error("Illegal host name: " + getServerName(), ex); throw new IllegalArgumentException("Cannot identify host " + getServerName()); } try { Socket socket = new Socket(serverAddress, getServerPort()); InputStream is = socket.getInputStream(); OutputStream os = socket.getOutputStream(); _messageSender = new ByteArrayFudgeMessageSender(new OutputStreamByteArrayMessageSender(os)); login(is); InputStreamFudgeMessageDispatcher messageDispatcher = new InputStreamFudgeMessageDispatcher(is, this); Thread t = new Thread(messageDispatcher, "CogdaLiveDataClient Dispatch Thread"); t.setDaemon(true); t.start(); _socketReadThread = t; _socket = socket; } catch (IOException ioe) { s_logger.error("Unable to establish connection to" + getServerName() + ":" + getServerPort(), ioe); throw new OpenGammaRuntimeException( "Unable to establish connection to" + getServerName() + ":" + getServerPort()); } }
From source file:net.bluehornreader.service.FeedCrawlerService.java
FeedCrawlerService(LowLevelDbAccess lowLevelDbAccess) throws Exception { crawlerDb = new Crawler.DB(lowLevelDbAccess); crawler = crawlerDb.getCrawler(IP);//from ww w . ja v a2 s. c om while (crawler == null) { synchronized (this) { wait(1000); } crawlerDb.updateCrawl(IP, 0); crawler = crawlerDb.getCrawler(IP); } crawler.feedIdsSeq = -1; // to force feeds to be read feedDb = new Feed.DB(lowLevelDbAccess); articleDb = new Article.DB(lowLevelDbAccess); electionDb = new Election.DB(lowLevelDbAccess); //clearFeeds(); System.exit(1); for (int i = 0; i < Config.getConfig().threadsPerCrawler; ++i) { Thread t = new CrawlingThread(); t.setDaemon(true); t.setName(String.format("CrawlingThread/%s/%s", IP, i)); crawlingRunnables.add(t); t.start(); } }
From source file:edu.umn.cs.spatialHadoop.visualization.MultilevelPlot.java
public static Job plot(Path[] inPaths, Path outPath, Class<? extends Plotter> plotterClass, OperationsParams params) throws IOException, InterruptedException, ClassNotFoundException { if (params.getBoolean("showmem", false)) { // Run a thread that keeps track of used memory Thread memThread = new Thread(new Thread() { @Override/*from ww w . j a v a2 s . co m*/ public void run() { Runtime runtime = Runtime.getRuntime(); while (true) { try { Thread.sleep(60000); } catch (InterruptedException e) { e.printStackTrace(); } runtime.gc(); LOG.info("Memory usage: " + ((runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024 * 1024)) + "GB."); } } }); memThread.setDaemon(true); memThread.start(); } // Decide how to run it based on range of levels to generate String[] strLevels = params.get("levels", "7").split("\\.\\."); int minLevel, maxLevel; if (strLevels.length == 1) { minLevel = 0; maxLevel = Integer.parseInt(strLevels[0]) - 1; } else { minLevel = Integer.parseInt(strLevels[0]); maxLevel = Integer.parseInt(strLevels[1]); } // Create an output directory that will hold the output of the two jobs FileSystem outFS = outPath.getFileSystem(params); outFS.mkdirs(outPath); Job runningJob = null; if (OperationsParams.isLocal(params, inPaths)) { // Plot local plotLocal(inPaths, outPath, plotterClass, params); } else { int maxLevelWithFlatPartitioning = params.getInt(FlatPartitioningLevelThreshold, 4); if (minLevel <= maxLevelWithFlatPartitioning) { OperationsParams flatPartitioning = new OperationsParams(params); flatPartitioning.set("levels", minLevel + ".." + Math.min(maxLevelWithFlatPartitioning, maxLevel)); flatPartitioning.set("partition", "flat"); LOG.info("Using flat partitioning in levels " + flatPartitioning.get("levels")); runningJob = plotMapReduce(inPaths, new Path(outPath, "flat"), plotterClass, flatPartitioning); } if (maxLevel > maxLevelWithFlatPartitioning) { OperationsParams pyramidPartitioning = new OperationsParams(params); pyramidPartitioning.set("levels", Math.max(minLevel, maxLevelWithFlatPartitioning + 1) + ".." + maxLevel); pyramidPartitioning.set("partition", "pyramid"); LOG.info("Using pyramid partitioning in levels " + pyramidPartitioning.get("levels")); runningJob = plotMapReduce(inPaths, new Path(outPath, "pyramid"), plotterClass, pyramidPartitioning); } // Write a new HTML file that displays both parts of the pyramid // Add an HTML file that visualizes the result using Google Maps LineReader templateFileReader = new LineReader( MultilevelPlot.class.getResourceAsStream("/zoom_view.html")); PrintStream htmlOut = new PrintStream(outFS.create(new Path(outPath, "index.html"))); Text line = new Text(); while (templateFileReader.readLine(line) > 0) { String lineStr = line.toString(); lineStr = lineStr.replace("#{TILE_WIDTH}", Integer.toString(params.getInt("tilewidth", 256))); lineStr = lineStr.replace("#{TILE_HEIGHT}", Integer.toString(params.getInt("tileheight", 256))); lineStr = lineStr.replace("#{MAX_ZOOM}", Integer.toString(maxLevel)); lineStr = lineStr.replace("#{MIN_ZOOM}", Integer.toString(minLevel)); lineStr = lineStr.replace("#{TILE_URL}", "(zoom <= " + maxLevelWithFlatPartitioning + "? 'flat' : 'pyramid')+('/tile-' + zoom + '-' + coord.x + '-' + coord.y + '.png')"); htmlOut.println(lineStr); } templateFileReader.close(); htmlOut.close(); } return runningJob; }
From source file:com.frostwire.android.gui.Librarian.java
public void syncMediaStore(final WeakReference<Context> contextRef) { if (!SystemUtils.isPrimaryExternalStorageMounted()) { return;/*from w w w . j av a 2 s.co m*/ } Thread t = new Thread(() -> syncMediaStoreSupport(contextRef)); t.setName("syncMediaStore"); t.setDaemon(true); t.start(); }