List of usage examples for java.lang Thread start
public synchronized void start()
From source file:at.ac.ait.ubicity.fileloader.FileLoader.java
/** * /*from ww w . j av a 2 s.co m*/ * @param _fileInfo A FileInformation object representing usage information on the file we are supposed to load: line count already ingested, last usage time... * @param _keySpace Cassandra key space into which to ingest * @param _host Cassandra host / server * @param _batchSize MutationBatch size * @throws Exception Shouldn't happen, although the Disruptor may throw an Exception under duress */ @SuppressWarnings("unchecked") public final static void load(final FileInformation _fileInfo, final String _keySpace, final String _host, final int _batchSize) throws Exception { if (!cassandraInitialized) { keySpace = AstyanaxInitializer.doInit("Test Cluster", _host, _keySpace); cassandraInitialized = true; } LongTimeStampSorter tsSorter = new LongTimeStampSorter(); Thread tTSSorter = new Thread(tsSorter); tTSSorter.setPriority(Thread.MAX_PRIORITY - 1); tTSSorter.setName("long timestamp sorter "); tTSSorter.start(); //get the log id from the file's URI final String log_id = _fileInfo.getURI().toString(); final MutationBatch batch = keySpace.prepareMutationBatch(); logger.info("got keyspace " + keySpace.getKeyspaceName() + " from Astyanax initializer"); final LineIterator onLines = FileUtils.lineIterator(new File(_fileInfo.getURI())); final ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); ColumnFamily crawl_stats = null; AggregationJob aggregationJob = new AggregationJob(keySpace, crawl_stats); Thread tAggJob = new Thread(aggregationJob); tAggJob.setName("Monitrix loader / aggregation job "); tAggJob.setPriority(Thread.MIN_PRIORITY + 1); tAggJob.start(); logger.info("[FILELOADER] started aggregation job, ring buffer running"); final Disruptor<SingleLogLineAsString> disruptor = new Disruptor(SingleLogLineAsString.EVENT_FACTORY, (int) Math.pow(TWO, 17), exec); SingleLogLineAsStringEventHandler.batch = batch; SingleLogLineAsStringEventHandler.keySpace = keySpace; SingleLogLineAsStringEventHandler.batchSize = _batchSize; SingleLogLineAsStringEventHandler.LOG_ID = log_id; SingleLogLineAsStringEventHandler.tsSorter = tsSorter; SingleLogLineAsStringEventHandler.aggregationJob = aggregationJob; //The EventHandler contains the actual logic for ingesting final EventHandler<SingleLogLineAsString> handler = new SingleLogLineAsStringEventHandler(); disruptor.handleEventsWith(handler); //get our Aggregate job in place //we are almost ready to start final RingBuffer<SingleLogLineAsString> rb = disruptor.start(); int _lineCount = 0; long _start, _lapse; _start = System.nanoTime(); int _linesAlreadyProcessed = _fileInfo.getLineCount(); //cycle through the lines already processed while (_lineCount < _linesAlreadyProcessed) { onLines.nextLine(); _lineCount++; } //now get down to the work we actually must do, and fill the ring buffer logger.info("begin proccessing of file " + _fileInfo.getURI() + " @line #" + _lineCount); while (onLines.hasNext()) { final long _seq = rb.next(); final SingleLogLineAsString event = rb.get(_seq); event.setValue(onLines.nextLine()); rb.publish(_seq); _lineCount++; } _lapse = System.nanoTime() - _start; logger.info("ended proccessing of file " + _fileInfo.getURI() + " @line #" + _lineCount); //stop, waiting for last threads still busy to finish their work disruptor.shutdown(); //update the file info, this will land in the cache _fileInfo.setLineCount(_lineCount); _fileInfo.setLastAccess(System.currentTimeMillis()); int _usageCount = _fileInfo.getUsageCount(); _fileInfo.setUsageCount(_usageCount++); //make sure we release resources onLines.close(); logger.info( "handled " + (_lineCount - _linesAlreadyProcessed) + " log lines in " + _lapse + " nanoseconds"); //now go to aggregation step SortedSet<Long> timeStamps = new TreeSet(tsSorter.timeStamps); long _minTs = timeStamps.first(); long _maxTs = timeStamps.last(); logger.info("**** min TimeStamp = " + _minTs); logger.info("**** max TimeStamp = " + _maxTs); StatsTableActualizer.update(_fileInfo.getURI().toString(), _minTs, _maxTs, _lineCount); // AggregationJob aggJob = new AggregationJob( keySpace, _host, _batchSize ); // Thread tAgg = new Thread( aggJob ); // tAgg.setName( "aggregation job " ); // tAgg.setPriority( Thread.MAX_PRIORITY - 1 ); // tAgg.start(); }
From source file:com.ariatemplates.seleniumjavarobot.Main.java
private static void closeOnStreamEnd(final SeleniumJavaRobot seleniumJavaRobot, final InputStream inputStream) { Thread thread = new Thread(new Runnable() { public void run() { try { while (inputStream.read() > -1) { // do nothing }//from w w w .j a va2 s . c o m } catch (IOException e) { } try { seleniumJavaRobot.stop(); } catch (InterruptedException e) { } } }); thread.setDaemon(true); thread.start(); }
From source file:com.offbynull.voip.ui.UiWebRegion.java
public static UiWebRegion create(Bus busFromGateway, Bus busToGateway) { UiWebRegion ret = new UiWebRegion(busFromGateway, busToGateway); URL resource = ret.getClass().getResource("/index.html"); Validate.validState(resource != null); // should never happen, sanity check String mainPageLink = resource.toExternalForm(); ret.webEngine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> { if (newState == State.SUCCEEDED) { JSObject win = (JSObject) ret.webEngine.executeScript("window"); win.setMember("messageSender", ret.new JavascriptToGatewayBridge()); busToGateway.add(new UiAction(new ReadyAction(false))); } else if (newState == State.CANCELLED || newState == State.FAILED) { busToGateway.add(new UiAction(new ReadyAction(true))); }//from w w w . ja v a2 s. co m }); ret.webEngine.load(mainPageLink); // This block makes sure to kill the incoming message pump if this webregion is removed from its parent, and (re)starts it if its // added // // NOTE: CANNOT USE PARENTPROPERTY -- PARENTPROPERTY ALWAYS RETURNS NULL FOR WHATEVER REASON ret.sceneProperty().addListener((observable, oldValue, newValue) -> { ret.lock.lock(); try { if (oldValue != null) { ret.incomingMessagePumpThread.interrupt(); ret.incomingMessagePumpThread.join(); ret.incomingMessagePumpThread = null; } if (newValue != null) { Thread thread = new Thread(ret.new GatewayToJavascriptPump()); thread.setDaemon(true); thread.setName(UiWebRegion.class.getSimpleName() + "-GatewayToJavascriptPump"); thread.start(); ret.incomingMessagePumpThread = thread; } } catch (InterruptedException ex) { throw new IllegalStateException(ex); } finally { ret.lock.unlock(); } }); return ret; }
From source file:net.objectlab.kit.console.ConsoleMenu.java
/** * @param prompt//from ww w .ja v a2s. com * The prompt to display to the user. * @return The password as entered by the user. */ public static String getPassword(final String prompt) { try { // password holder final StringBuilder password = new StringBuilder(); final PasswordHidingThread maskingthread = new PasswordHidingThread(prompt); final Thread thread = new Thread(maskingthread); thread.start(); // block until enter is pressed while (true) { char c = (char) System.in.read(); // assume enter pressed, stop masking maskingthread.stopMasking(); if (c == '\r') { c = (char) System.in.read(); if (c == '\n') { break; } continue; } else if (c == '\n') { break; } else { // store the password password.append(c); } } return password.toString(); } catch (final IOException e) { log(e); } return null; }
From source file:com.excuseme.rocketleaguelivestats.scanner.tailer.Tailer.java
/** * Creates and starts a Tailer for the given file. * * @param file the file to follow.//w w w .ja va 2s . c om * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. * @param bufSize buffer size. * @return The new tailer */ public static Tailer create(File file, TailerListener listener, long delayMillis, boolean end, int bufSize) { Tailer tailer = new Tailer(file, listener, delayMillis, end, bufSize); Thread thread = new Thread(tailer); thread.setDaemon(true); thread.start(); return tailer; }
From source file:com.excuseme.rocketleaguelivestats.scanner.tailer.Tailer.java
/** * Creates and starts a Tailer for the given file. * * @param file the file to follow.//w w w .j av a 2 s .c o m * @param listener the TailerListener to use. * @param delayMillis the delay between checks of the file for new content in milliseconds. * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. * @param reOpen whether to close/reopen the file between chunks * @param bufSize buffer size. * @return The new tailer */ public static Tailer create(File file, TailerListener listener, long delayMillis, boolean end, boolean reOpen, int bufSize) { Tailer tailer = new Tailer(file, listener, delayMillis, end, reOpen, bufSize); Thread thread = new Thread(tailer); thread.setDaemon(true); thread.start(); return tailer; }
From source file:net.bither.util.TransactionsUtil.java
public static Thread completeInputsForAddressInBackground(final Address address) { Thread thread = new Thread() { @Override/*from w w w . j av a 2 s.c o m*/ public void run() { completeInputsForAddress(address); } }; thread.setPriority(Thread.MIN_PRIORITY); thread.start(); return thread; }
From source file:com.taxicop.client.NetworkUtilities.java
public static Thread performOnBackgroundThread(final Runnable runnable) { final Thread t = new Thread() { @Override//from w w w .j a va 2s . c o m public void run() { try { runnable.run(); } finally { } } }; t.start(); return t; }
From source file:com.nesscomputing.syslog4j.server.SyslogServer.java
public static final SyslogServerIF getThreadedInstance(String protocol) throws SyslogRuntimeException { SyslogServerIF server = getInstance(protocol); if (server.getThread() == null) { Thread thread = new Thread(server); thread.setName("SyslogServer: " + protocol); thread.setDaemon(server.getConfig().isUseDaemonThread()); if (server.getConfig().getThreadPriority() > -1) { thread.setPriority(server.getConfig().getThreadPriority()); }//from ww w .ja v a2 s . c o m server.setThread(thread); thread.start(); } return server; }
From source file:Main.java
public static CountDownLatch execute(int threadCount, final Runnable task) { final CountDownLatch startSignal = new CountDownLatch(1); final CountDownLatch startedSignal = new CountDownLatch(threadCount); final CountDownLatch doneSignal = new CountDownLatch(threadCount); for (int i = 0; i < threadCount; i++) { Thread t = new Thread() { public void run() { startedSignal.countDown(); try { startSignal.await(); } catch (InterruptedException e) { //ignore }/*from w w w . j ava 2s. c o m*/ try { task.run(); } finally { doneSignal.countDown(); } } }; t.start(); } try { startedSignal.await(); } catch (InterruptedException e) { //ignore } startSignal.countDown(); return doneSignal; }