List of usage examples for java.lang Thread setName
public final synchronized void setName(String name)
From source file:fs.MainWindow.java
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed jProgressBarSE.setValue(0);/*from w w w . j av a 2 s . c o m*/ double alpha = (Double) jS_AlphaSE.getValue(); double q_entropy = (Double) jS_QEntropySE.getValue(); if (q_entropy < 0 || alpha < 0) { //entrada de dados invalida. JOptionPane.showMessageDialog(null, "Error on parameter value:" + " The values of q-entropy and Alpha must be positives.", "Application Error", JOptionPane.ERROR_MESSAGE); return; } class Thread1 extends Thread { @Override public void run() { try { if (jRB_SFSSE.isSelected()) { ExecuteFeatureSelection(1);// SFS } else if (jRB_ESSE.isSelected()) { ExecuteFeatureSelection(2);// ExhaustiveSearch } else if (jRB_SFFSSE.isSelected()) { ExecuteFeatureSelection(3);// SFFS } else { JOptionPane.showMessageDialog(null, "Select Feature " + "Selector must be marked.", "Error", JOptionPane.ERROR_MESSAGE); } } catch (IOException error) { throw new FSException("Error on Execution of the Search" + " Method." + error, false); } } } Thread thread = new Thread1(); thread.setPriority(Thread.NORM_PRIORITY); thread.setName("SE"); thread.start(); }
From source file:fs.MainWindow.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed double alpha = (Double) jS_AlphaCV.getValue(); double q_entropy = (Double) jS_QEntropyCV.getValue(); if (q_entropy < 0 || alpha < 0) { //entrada de dados invalida. JOptionPane.showMessageDialog(null, "Error on parameter value:" + " The values of q-entropy and Alpha must be positives.", "Application Error", JOptionPane.ERROR_MESSAGE); return;//from www .j a v a 2s . co m } class ThreadCV extends Thread { @Override public void run() { try { if (jRB_SFSCV.isSelected()) { CrossValidation((Integer) jS_NrExecutionsCV.getValue(), ((float) jSliderCV.getValue()) / 100, 1);// SFS } else if (jRB_ESCV.isSelected()) { CrossValidation((Integer) jS_NrExecutionsCV.getValue(), ((float) jSliderCV.getValue()) / 100, 2);//ExhaustiveSearch } else if (jRB_SFFSCV.isSelected()) { CrossValidation((Integer) jS_NrExecutionsCV.getValue(), ((float) jSliderCV.getValue()) / 100, 3);// SFFS } else { JOptionPane.showMessageDialog(null, "Select Feature " + "Selector must be marked.", "Error", JOptionPane.ERROR_MESSAGE); } } catch (IOException error) { throw new FSException("Error on Cross-validation." + error, false); } } } Thread thread = new ThreadCV(); thread.setPriority(Thread.NORM_PRIORITY); thread.setName("CV"); thread.start(); }
From source file:edu.umass.cs.gigapaxos.PaxosManager.java
/** * @param id/* ww w . j a va 2s.co m*/ * My node ID. * @param unstringer * An instance of Stringifiable that can convert String to * NodeIDType. * @param niot * InterfaceNIOTransport or InterfaceMessenger object used for * messaging. * @param pi * InterfaceReplicable application controlled by gigapaxos. * Currently, all paxos instances must correspond to a single * umbrella application even though each createPaxosInstance * method explicitly specifies the app and this information is * stored explicitly inside a paxos instance. The reason for the * single umbrella app restriction is that we won't have a * pointer to the appropriate app upon recovery otherwise. * @param paxosLogFolder * Paxos logging folder. * @param enableNullCheckpoints * Whether null checkpoints are enabled. We need this flag to be * enabled if we intend to reconfigure paxos groups managed by * this PaxosManager. Otherwise, we can not distinguish between a * null checkpoint and no checkpoint, so the next epoch members * may be waiting forever for the previous epoch's final state * (that happens to be null). This flag needs to be set at * construction time and can not be changed thereafter. */ public PaxosManager(NodeIDType id, Stringifiable<NodeIDType> unstringer, InterfaceNIOTransport<NodeIDType, JSONObject> niot, Replicable pi, String paxosLogFolder, boolean enableNullCheckpoints) { this.myID = this.integerMap.put(id);// id.hashCode(); this.executor = Executors.newScheduledThreadPool(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread thread = Executors.defaultThreadFactory().newThread(r); thread.setName(PaxosManager.class.getSimpleName() + myID); return thread; } }); this.unstringer = unstringer; this.largeCheckpointer = new LargeCheckpointer(paxosLogFolder, this.myID + ""); this.myApp = LargeCheckpointer.wrap(pi, largeCheckpointer); this.FD = new FailureDetection<NodeIDType>(id, niot, paxosLogFolder); this.pinstances = new MultiArrayMap<String, PaxosInstanceStateMachine>( Config.getGlobalInt(PC.PINSTANCES_CAPACITY)); this.corpses = new HashMap<String, PaxosInstanceStateMachine>(); // this.activePaxii = new HashMap<String, ActivePaxosState>(); this.messenger = (new PaxosMessenger<NodeIDType>(niot, this.integerMap)); this.paxosLogger = new SQLPaxosLogger(this.myID, id.toString(), paxosLogFolder, this.wrapMessenger(this.messenger)); this.nullCheckpointsEnabled = enableNullCheckpoints; // periodically remove active state for idle paxii executor.scheduleWithFixedDelay(new Deactivator(), 0, Config.getGlobalInt(PC.DEACTIVATION_PERIOD), TimeUnit.MILLISECONDS); this.pendingDigests = new PendingDigests(this.outstanding.requests, Config.getGlobalInt(PC.NUM_MESSAGE_DIGESTS), new PendingDigests.PendingDigestCallback() { public void callback(AcceptPacket accept) { PaxosManager.this.callbackDigestedAcceptTimeout(accept); } }); this.initOutstandingMonitor(); (this.requestBatcher = new RequestBatcher(this)).start(); (this.ppBatcher = new PaxosPacketBatcher(this)).start(); testingInitialization(); // needed to unclose when testing multiple runs of open and close open(); // so paxos packets will come to me before anyone else niot.precedePacketDemultiplexer( Config.getGlobalString(PC.JSON_LIBRARY).equals("org.json") ? new JSONDemultiplexer() : new FastDemultiplexer()); initiateRecovery(); if (!Config.getGlobalBoolean(PC.DELAY_PROFILER)) DelayProfiler.disable(); }
From source file:com.mellanox.r4h.DFSClient.java
/** * Create hedged reads thread pool, HEDGED_READ_THREAD_POOL, if * it does not already exist.//from ww w. j a va2 s . c o m * * @param num * Number of threads for hedged reads thread pool. * If zero, skip hedged reads thread pool creation. */ private synchronized void initThreadsNumForHedgedReads(int num) { if (num <= 0 || HEDGED_READ_THREAD_POOL != null) return; HEDGED_READ_THREAD_POOL = new ThreadPoolExecutor(1, num, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new Daemon.DaemonFactory() { private final AtomicInteger threadIndex = new AtomicInteger(0); @Override public Thread newThread(Runnable r) { Thread t = super.newThread(r); t.setName("hedgedRead-" + threadIndex.getAndIncrement()); return t; } }, new ThreadPoolExecutor.CallerRunsPolicy() { @Override public void rejectedExecution(Runnable runnable, ThreadPoolExecutor e) { LOG.info("Execution rejected, Executing in current thread"); HEDGED_READ_METRIC.incHedgedReadOpsInCurThread(); // will run in the current thread super.rejectedExecution(runnable, e); } }); HEDGED_READ_THREAD_POOL.allowCoreThreadTimeOut(true); if (LOG.isDebugEnabled()) { LOG.debug("Using hedged reads; pool threads=" + num); } }
From source file:mondrian.olap.Util.java
/** * Creates an {@link ScheduledExecutorService} object backed by a * thread pool with a fixed number of threads.. * @param maxNbThreads Maximum number of concurrent * threads.//from www . j a v a 2 s.c o m * @param name The name of the threads. * @return An scheduled executor service preconfigured. */ public static ScheduledExecutorService getScheduledExecutorService(final int maxNbThreads, final String name) { return Executors.newScheduledThreadPool(maxNbThreads, new ThreadFactory() { final AtomicInteger counter = new AtomicInteger(0); public Thread newThread(Runnable r) { final Thread thread = Executors.defaultThreadFactory().newThread(r); thread.setDaemon(true); thread.setName(name + '_' + counter.incrementAndGet()); return thread; } }); }
From source file:mondrian.olap.Util.java
/** * Creates an {@link ExecutorService} object backed by a thread pool. * @param maximumPoolSize Maximum number of concurrent * threads./*w ww. j a v a2 s .co m*/ * @param corePoolSize Minimum number of concurrent * threads to maintain in the pool, even if they are * idle. * @param keepAliveTime Time, in seconds, for which to * keep alive unused threads. * @param name The name of the threads. * @param rejectionPolicy The rejection policy to enforce. * @return An executor service preconfigured. */ public static ExecutorService getExecutorService(int maximumPoolSize, int corePoolSize, long keepAliveTime, final String name, RejectedExecutionHandler rejectionPolicy) { if (Util.PreJdk16) { // On JDK1.5, if you specify corePoolSize=0, nothing gets executed. // Bummer. corePoolSize = Math.max(corePoolSize, 1); } // We must create a factory where the threads // have the right name and are marked as daemon threads. final ThreadFactory factory = new ThreadFactory() { private final AtomicInteger counter = new AtomicInteger(0); public Thread newThread(Runnable r) { final Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); t.setName(name + '_' + counter.incrementAndGet()); return t; } }; // Ok, create the executor final ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize > 0 ? maximumPoolSize : Integer.MAX_VALUE, keepAliveTime, TimeUnit.SECONDS, // we use a sync queue. any other type of queue // will prevent the tasks from running concurrently // because the executors API requires blocking queues. // Important to pass true here. This makes the // order of tasks deterministic. // TODO Write a non-blocking queue which implements // the blocking queue API so we can pass that to the // executor. new SynchronousQueue<Runnable>(true), factory); // Set the rejection policy if required. if (rejectionPolicy != null) { executor.setRejectedExecutionHandler(rejectionPolicy); } // Done return executor; }
From source file:com.frostwire.gui.bittorrent.SoundcloudTrackUrlDownload.java
private void start() { Thread t = new Thread(new Runnable() { @Override//from www. j a v a 2 s.co m public void run() { try { LinkCollector collector = LinkCollector.getInstance(); LinkCrawler crawler = new LinkCrawler(); crawler.setFilter(LinkFilterController.getInstance()); crawler.crawl(trackUrl); crawler.waitForCrawling(); if (_state.equals(STATE_STOPPED)) { return; } _state = STATE_FINISHED; progress = 100; final List<FilePackage> packages = new ArrayList<FilePackage>(); for (CrawledLink link : crawler.getCrawledLinks()) { CrawledPackage parent = createCrawledPackage(link); parent.setControlledBy(collector); link.setParentNode(parent); ArrayList<CrawledLink> links = new ArrayList<CrawledLink>(); links.add(link); packages.add(createFilePackage(parent, links)); } /* for (CrawledPackage pkg : new ArrayList<CrawledPackage>(collector.getPackages())) { for (CrawledLink link : new ArrayList<CrawledLink>(pkg.getChildren())) { ArrayList<CrawledLink> links = new ArrayList<CrawledLink>(); links.add(link); packages.addAll(collector.removeAndConvert(links)); } }*/ GUIMediator.safeInvokeAndWait(new Runnable() { public void run() { try { // we assume there is only one link for (FilePackage filePackage : packages) { BTDownloadMediator.instance().openSoundcloudItem(filePackage, title, sr); } } catch (Throwable e) { LOG.error("Error reading soundcloud package:" + e.getMessage(), e); _state = STATE_ERROR; } } }); GUIMediator.safeInvokeAndWait(new Runnable() { public void run() { BTDownloadMediator.instance().remove(SoundcloudTrackUrlDownload.this); } }); } catch (Throwable e) { LOG.error("Error crawling soundcloud: " + trackUrl, e); _state = STATE_ERROR; } } }); t.setDaemon(true); t.setName("Soundcloud Crawl: " + trackUrl); t.start(); }
From source file:org.apache.hadoop.mapred.CoronaJobTracker.java
public void startFailureEmulator() { FailureEmulator failureEmulator = new FailureEmulator(); Thread failureEmulatorThread = new Thread(failureEmulator); failureEmulatorThread.setDaemon(true); failureEmulatorThread.setName("Failure Emulator"); failureEmulatorThread.start();//from w w w . java 2 s . c om }
From source file:org.apache.hadoop.mapred.CoronaJobTracker.java
public void startLJTHealthMonitor() { LocalJobTrackerHealthMonitor ljtHealthMonitor = new LocalJobTrackerHealthMonitor(); Thread ljtHealthMonitorThread = new Thread(ljtHealthMonitor); ljtHealthMonitorThread.setDaemon(true); ljtHealthMonitorThread.setName("Local JobTracker Health Monitor"); ljtHealthMonitorThread.start();// w w w . j a v a 2s .com }
From source file:org.apache.hadoop.mapred.CoronaJobTracker.java
/** * Constructor for the remote job tracker (running in cluster). * @param conf Configuration/*from w w w . j ava2 s.c om*/ * @param jobId Job ID. * @param attemptId attempt ID * @param parentAddr Address of the parent job tracker * @throws IOException */ public CoronaJobTracker(JobConf conf, JobID jobId, TaskAttemptID attemptId, InetSocketAddress parentAddr) throws IOException { this.isStandalone = true; this.heartbeatInterval = conf.getInt(HEART_BEAT_INTERVAL_KEY, 3000); this.grantsPerIteration = conf.getInt(GRANTS_PROCESS_PER_ITERATION, 100); this.maxEventsPerRpc = conf.getInt(TASK_COMPLETION_EVENTS_PER_RPC, 100); this.remoteJT = null; // This is already a standalone (remote) CJT, unset the flag. conf.setBoolean("mapred.coronajobtracker.forceremote", false); this.conf = conf; this.trackerStats = new TrackerStats(conf); this.fs = FileSystem.get(conf); this.jobId = jobId; this.tid = attemptId; this.parentAddr = parentAddr; this.jtAttemptId = attemptId; if (RemoteJTProxy.isStateRestoringEnabled(conf)) { // Initialize parent client parentClient = RPC.waitForProxy(InterCoronaJobTrackerProtocol.class, InterCoronaJobTrackerProtocol.versionID, parentAddr, conf, RemoteJTProxy.getRemotJTTimeout(conf)); // Fetch saved state and prepare for application stateFetcher = new Fetcher(parentClient, jtAttemptId); // Remote JT should ask local for permission to commit commitPermissionClient = new CommitPermissionClient(attemptId, parentAddr, conf); } else { stateFetcher = new Fetcher(); commitPermissionClient = new CommitPermissionClient(); } // Start with dummy submitter until saved state is restored localJTSubmitter = new Submitter(); initializePJTClient(); // add this job tracker to cgroup Configuration remoteConf = new Configuration(); if (remoteConf.getBoolean("mapred.jobtracker.cgroup.mem", false)) { String pid = System.getenv().get("JVM_PID"); LOG.info("Add " + attemptId + " " + pid + " to JobTracker CGroup"); JobTrackerMemoryControlGroup jtMemCgroup = new JobTrackerMemoryControlGroup(remoteConf); jtMemCgroup.addJobTracker(attemptId.toString(), pid); } createSession(); startFullTracker(); // In remote mode, we have a parent JT that we need to communicate with. parentHeartbeat = new ParentHeartbeat(conf, attemptId, jobTrackerAddress, parentAddr, sessionId); try { // Perform an initial heartbeat to confirm that we can go ahead. // If this throws an exception, the rest of the threads are daemon // threads, so the stand-alone CJT will exit. parentHeartbeat.initialHeartbeat(); // Start the thread to do periodic heartbeats. // This thread is not a daemon thread, so the process will hang around // while it is alive. Thread parentHeartbeatThread = new Thread(parentHeartbeat); parentHeartbeatThread.setDaemon(false); parentHeartbeatThread.setName("Parent Heartbeat"); parentHeartbeatThread.start(); Thread parentHeartbeatMonitorThread = new Thread(new ParentHeartbeatMonitor(parentHeartbeat)); parentHeartbeatMonitorThread.setDaemon(true); parentHeartbeatMonitorThread.setName("Parent Heartbeat Monitor"); parentHeartbeatMonitorThread.start(); } catch (IOException e) { LOG.error("Closing CJT after initial heartbeat error", e); try { close(false); } catch (InterruptedException e1) { } finally { // Ensures that the process will exit (some non-daemon // threads might hang on unclean exit) System.exit(1); } } }