List of usage examples for java.lang Thread join
public final void join() throws InterruptedException
From source file:fitnesse.FitNesseExpediterTest.java
@Test public void testSlowButCompleteRequest() throws Exception { final FitNesseExpediter sender = preparePipedFitNesseExpediter(); Thread senderThread = makeSendingThread(sender); senderThread.start();/*from w ww.j a va2 s . c o m*/ Thread parseResponseThread = makeParsingThread(); parseResponseThread.start(); byte[] bytes = "GET /root HTTP/1.1\r\n\r\n".getBytes(); try { for (byte aByte : bytes) { clientOutput.write(aByte); clientOutput.flush(); Thread.sleep(20); } } catch (IOException pipedClosed) { } parseResponseThread.join(); assertEquals(200, response.getStatus()); }
From source file:com.espertech.esper.regression.nwtable.TestTableMTAccessReadMergeWriteInsertDeleteRowVisible.java
private void tryMT(int numSeconds, boolean grouped) throws Exception { String eplCreateTable = "create table MyTable (key string " + (grouped ? "primary key" : "") + ", p0 int, p1 int, p2 int, p3 int, p4 int, p5 int)"; epService.getEPAdministrator().createEPL(eplCreateTable); String eplSelect = grouped/*from ww w. j a v a 2 s . c o m*/ ? "select MyTable['K1'].p0 as c0, MyTable['K1'].p1 as c1, MyTable['K1'].p2 as c2, " + "MyTable['K1'].p3 as c3, MyTable['K1'].p4 as c4, MyTable['K1'].p5 as c5 from SupportBean_S0" : "select MyTable.p0 as c0, MyTable.p1 as c1, MyTable.p2 as c2, " + "MyTable.p3 as c3, MyTable.p4 as c4, MyTable.p5 as c5 from SupportBean_S0"; EPStatement stmt = epService.getEPAdministrator().createEPL(eplSelect); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); String eplMerge = "on SupportBean merge MyTable " + "when not matched then insert select 'K1' as key, 1 as p0, 1 as p1, 1 as p2, 1 as p3, 1 as p4, 1 as p5 " + "when matched then delete"; epService.getEPAdministrator().createEPL(eplMerge); WriteRunnable writeRunnable = new WriteRunnable(epService); ReadRunnable readRunnable = new ReadRunnable(epService, listener); // start Thread t1 = new Thread(writeRunnable); Thread t2 = new Thread(readRunnable); t1.start(); t2.start(); // wait Thread.sleep(numSeconds * 1000); // shutdown writeRunnable.setShutdown(true); readRunnable.setShutdown(true); // join log.info("Waiting for completion"); t1.join(); t2.join(); assertNull(writeRunnable.getException()); assertTrue(writeRunnable.numEvents > 100); assertNull(readRunnable.getException()); assertTrue(readRunnable.numQueries > 100); assertTrue(readRunnable.getNotFoundCount() > 2); assertTrue(readRunnable.getFoundCount() > 2); System.out.println( "Send " + writeRunnable.numEvents + " and performed " + readRunnable.numQueries + " reads (found " + readRunnable.getFoundCount() + ") (not found " + readRunnable.getNotFoundCount() + ")"); }
From source file:org.huahinframework.manager.Runner.java
/** * @param war/*from w w w . ja v a2 s. c o m*/ * @param port */ public void start(String war, int port) { log.info("huahin-manager start"); ConfigurableApplicationContext applicationContext = null; try { applicationContext = new ClassPathXmlApplicationContext("huahinManagerProperties.xml"); Properties properties = (Properties) applicationContext.getBean("properties"); Thread queueManager = new QueueManager(properties); queueManager.start(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(port); Server server = new Server(); server.setConnectors(new Connector[] { connector }); WebAppContext web = new WebAppContext(); web.setContextPath("/"); web.setWar(war); server.addHandler(web); server.start(); server.join(); queueManager.join(); } catch (Exception e) { log.error("huahin-manager aborted", e); System.exit(-1); } log.info("huahin-manager end"); }
From source file:com.espertech.esper.regression.nwtable.TestTableMTGroupedSubqueryReadInsertIntoWriteConcurr.java
private void tryMT(int numSeconds) throws Exception { String eplCreateVariable = "create table MyTable (pkey string primary key)"; epService.getEPAdministrator().createEPL(eplCreateVariable); String eplInsertInto = "insert into MyTable select theString as pkey from SupportBean"; epService.getEPAdministrator().createEPL(eplInsertInto); // seed with count 1 epService.getEPRuntime().sendEvent(new SupportBean("E0", 0)); // select/read String eplSubselect = "select (select count(*) from MyTable) as c0 from SupportBean_S0"; EPStatement stmtSubselect = epService.getEPAdministrator().createEPL(eplSubselect); SupportUpdateListener listener = new SupportUpdateListener(); stmtSubselect.addListener(listener); WriteRunnable writeRunnable = new WriteRunnable(epService); ReadRunnable readRunnable = new ReadRunnable(epService, listener); // start//w w w . jav a 2 s. c o m Thread writeThread = new Thread(writeRunnable); Thread readThread = new Thread(readRunnable); writeThread.start(); readThread.start(); // wait Thread.sleep(numSeconds * 1000); // shutdown writeRunnable.setShutdown(true); readRunnable.setShutdown(true); // join log.info("Waiting for completion"); writeThread.join(); readThread.join(); assertNull(writeRunnable.getException()); assertNull(readRunnable.getException()); assertTrue(writeRunnable.numLoops > 100); assertTrue(readRunnable.numQueries > 100); System.out .println("Send " + writeRunnable.numLoops + " and performed " + readRunnable.numQueries + " reads"); }
From source file:com.espertech.esper.regression.nwtable.TestTableMTUngroupedJoinColumnConsistency.java
private void tryMT(int numSeconds) throws Exception { String epl = "create table MyTable (p0 string, p1 string, p2 string, p3 string, p4 string);\n" + "on SupportBean merge MyTable " + " when not matched then insert select '1' as p0, '1' as p1, '1' as p2, '1' as p3, '1' as p4;\n" + "on SupportBean_S0 merge MyTable " + " when matched then update set p0=p00, p1=p00, p2=p00, p3=p00, p4=p00;\n" + "@name('out') select p0 from SupportBean_S1 unidirectional, MyTable where " + "(p0='1' and p1='1' and p2='1' and p3='1' and p4='1')" + " or (p0='2' and p1='2' and p2='2' and p3='2' and p4='2')" + ";\n"; epService.getEPAdministrator().getDeploymentAdmin().parseDeploy(epl); // preload/*from w w w. j a v a 2 s .c o m*/ epService.getEPRuntime().sendEvent(new SupportBean()); Update_1_2_WriteRunnable writeRunnable = new Update_1_2_WriteRunnable(epService); ReadRunnable readRunnable = new ReadRunnable(epService); // start Thread threadWrite = new Thread(writeRunnable); Thread threadRead = new Thread(readRunnable); threadWrite.start(); threadRead.start(); // wait Thread.sleep(numSeconds * 1000); // shutdown writeRunnable.setShutdown(true); readRunnable.setShutdown(true); // join log.info("Waiting for completion"); threadWrite.join(); threadRead.join(); assertNull(writeRunnable.getException()); assertNull(readRunnable.getException()); System.out.println( "Write loops " + writeRunnable.numLoops + " and performed " + readRunnable.numQueries + " reads"); assertTrue(writeRunnable.numLoops > 1); assertTrue(readRunnable.numQueries > 100); }
From source file:com.thoughtworks.go.plugin.infra.service.DefaultPluginLoggingServiceIntegrationTest.java
@Test(timeout = 10 * 1000) public void shouldAllowLoggingAcrossMultipleThreadsAndPlugins() throws Exception { Thread thread1 = createThreadFor(pluginID(1), "1"); Thread thread2 = createThreadFor(pluginID(2), "2"); Thread thread3 = createThreadFor(pluginID(1), "3"); Thread thread4 = createThreadFor(pluginID(2), "4"); thread1.start();// w w w . ja v a2 s . c o m thread2.start(); thread3.start(); thread4.start(); thread1.join(); thread2.join(); thread3.join(); thread4.join(); assertNumberOfMessagesInLog(pluginLog(1), 200); assertNumberOfMessagesInLog(pluginLog(2), 200); }
From source file:com.espertech.esper.regression.nwtable.TestTableMTGroupedJoinReadMergeWriteSecondaryIndexUpd.java
private void tryMT(int numSeconds) throws Exception { String epl = "create table MyTable (key1 string primary key, value int);\n" + "create index MyIndex on MyTable (value);\n" + "on SupportBean merge MyTable where theString = key1 when not matched then insert select theString as key1, intPrimitive as value;\n" + "@name('out') select * from SupportBean_S0, MyTable where value = id;\n" + "on SupportBean_S1 delete from MyTable where key1 like 'B%';\n"; epService.getEPAdministrator().getDeploymentAdmin().parseDeploy(epl); // preload A_n events for (int i = 0; i < NUM_KEYS; i++) { epService.getEPRuntime().sendEvent(new SupportBean("A_" + i, i)); }//from ww w .j av a 2 s.c o m WriteRunnable writeRunnable = new WriteRunnable(epService); ReadRunnable readRunnable = new ReadRunnable(epService); // start Thread threadWrite = new Thread(writeRunnable); Thread threadRead = new Thread(readRunnable); threadWrite.start(); threadRead.start(); // wait Thread.sleep(numSeconds * 1000); // shutdown writeRunnable.setShutdown(true); readRunnable.setShutdown(true); // join log.info("Waiting for completion"); threadWrite.join(); threadRead.join(); assertNull(writeRunnable.getException()); assertNull(readRunnable.getException()); System.out.println( "Write loops " + writeRunnable.numLoops + " and performed " + readRunnable.numQueries + " reads"); assertTrue(writeRunnable.numLoops > 1); assertTrue(readRunnable.numQueries > 100); }
From source file:com.flipkart.flux.client.runtime.LocalContextTest.java
@Test public void shouldAllowSameMethodRegistrationFromDifferentThreads() throws Exception { final MutableObject<StateMachineDefinition> definitionOne = new MutableObject<>(null); final MutableObject<StateMachineDefinition> definitionTwo = new MutableObject<>(null); final Thread thread1 = new Thread(() -> { localContext.registerNew("fooBar", 1, "someDescription", "someContext"); definitionOne.setValue(tlStateMachineDef.get()); });/*from w w w .jav a2 s.co m*/ final Thread thread2 = new Thread(() -> { localContext.registerNew("fooBar", 1, "someDescription", "someContext"); definitionTwo.setValue(tlStateMachineDef.get()); }); thread1.start(); thread2.start(); thread1.join(); thread2.join(); assertThat(definitionOne.getValue()).isNotNull().isEqualTo(definitionTwo.getValue()) .isEqualTo(new StateMachineDefinition("someDescription", "fooBar", 1l, new HashSet<>(), new HashSet<>(), "someContext")); }
From source file:fi.jumi.core.stdout.OutputCapturerTest.java
@Test public void when_spawned_threads_print_something_after_the_capture_ends_they_are_still_include_in_the_original_capture() throws InterruptedException { CountDownLatch beforeFinished = new CountDownLatch(2); CountDownLatch afterFinished = new CountDownLatch(2); OutputListenerSpy capture1 = new OutputListenerSpy(); OutputListenerSpy capture2 = new OutputListenerSpy(); capturer.captureTo(capture1);/*from w w w . java 2 s . co m*/ Thread t = startThread(() -> { capturer.out().print("before capture finished"); sync(beforeFinished); sync(afterFinished); capturer.out().print("after capture finished"); }); sync(beforeFinished); capturer.captureTo(capture2); sync(afterFinished); t.join(); assertThat(capture1.out).containsExactly("before capture finished", "after capture finished"); assertThat(capture2.out).containsExactly(); }
From source file:com.deltachi.videotex.daos.UpdaterForMovies.java
public void run() { if (DAOSingleton.getInstance().torrentExists(t.getChecksum()) == false) { languages = DAOSingleton.getInstance().getLanguages(); Video retrievedVideo = DAOSingleton.getInstance().findVideoByImdbCode(imdbCode); if (retrievedVideo == null) { Video video = null;// ww w . j a v a 2 s.co m try { video = new IMDBGraber().getVideo(imdbCode); } catch (JSONException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); return; } catch (IOException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); return; } Collection<Genre> genreCollection = video.getGenreCollection(); GenreDAO[] genreUpdateThread = new GenreDAO[genreCollection.size()]; int i = 0; for (Genre g : genreCollection) { genreUpdateThread[i] = new GenreDAO(g); i++; } for (GenreDAO genreUpdateThread1 : genreUpdateThread) { genreUpdateThread1.start(); } for (GenreDAO genreUpdateThread1 : genreUpdateThread) { try { genreUpdateThread1.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } } VideoDAO videoUpdater = new VideoDAO(video); videoUpdater.start(); try { videoUpdater.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } video = DAOSingleton.getInstance().findVideoByImdbCode(video.getImdbCode()); MovieDAO movieUpdater = new MovieDAO(video); movieUpdater.start(); try { movieUpdater.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } Collection<Genre> genreCollection2 = new ArrayList<>(); genreCollection.stream().forEach((g) -> { genreCollection2.add(DAOSingleton.getInstance().findGenreByName(g.getName())); }); genreCollection = genreCollection2; VideoAndGenresAssociater vaga = new VideoAndGenresAssociater(video, genreCollection); vaga.start(); Collection<Screenshot> screenshotCollection = t.getScreenshotCollection(); int numberOfScreenshots = 0; if (screenshotCollection.isEmpty() == false) { numberOfScreenshots = screenshotCollection.size(); } t.setScreenshotCollection(new ArrayList<>()); TorrentDAO torrentUpdater = new TorrentDAO(t); torrentUpdater.start(); try { torrentUpdater.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } t = DAOSingleton.getInstance().findTorrentByChecksum(t.getChecksum()); Thread[] screenshotsThread = new Thread[numberOfScreenshots]; int j = 0; if (numberOfScreenshots > 0) { for (Screenshot s : screenshotCollection) { s.setTorrentID(t); screenshotsThread[j] = new ScreenshotDAO(s); j++; } } for (Thread t : screenshotsThread) { t.start(); } for (Thread t : screenshotsThread) { try { t.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } } Movie movie = DAOSingleton.getInstance().findVideoByImdbCode(video.getImdbCode()).getMovie(); MovieTorrent mt = new MovieTorrent(); t = DAOSingleton.getInstance().findTorrentByChecksum(t.getChecksum()); mt.setMovieID(movie); mt.setTorrent(t); mt.setTorrentID(t.getId()); MovieTorrentDAO mtUpdater = new MovieTorrentDAO(mt); mtUpdater.start(); try { mtUpdater.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } t.setMovieTorrent(mt); torrentUpdater = new TorrentDAO(t); torrentUpdater.start(); try { torrentUpdater.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } Collection<MovieTorrent> movieTorrentCollection = movie.getMovieTorrentCollection(); if ((movieTorrentCollection == null) || (movieTorrentCollection.isEmpty())) { movieTorrentCollection = new ArrayList<>(); } movieTorrentCollection.add(mt); movie.setMovieTorrentCollection(movieTorrentCollection); movieUpdater = new MovieDAO(video, movie); movieUpdater.start(); try { movieUpdater.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } this.completedSuccessfuly = true; } else { Collection<Screenshot> screenshotCollection = t.getScreenshotCollection(); int numberOfScreenshots = 0; if (screenshotCollection.isEmpty() == false) { numberOfScreenshots = screenshotCollection.size(); } t.setScreenshotCollection(new ArrayList<>()); TorrentDAO torrentUpdater = new TorrentDAO(t); torrentUpdater.start(); try { torrentUpdater.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } t = DAOSingleton.getInstance().findTorrentByChecksum(t.getChecksum()); Thread[] screenshotsThread = new Thread[numberOfScreenshots]; int j = 0; if (numberOfScreenshots > 0) { for (Screenshot s : screenshotCollection) { s.setTorrentID(t); screenshotsThread[j] = new ScreenshotDAO(s); j++; } } for (Thread t : screenshotsThread) { t.start(); } for (Thread t : screenshotsThread) { try { t.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } } Movie movie = DAOSingleton.getInstance().findVideoByImdbCode(retrievedVideo.getImdbCode()) .getMovie(); MovieTorrent mt = new MovieTorrent(); t = DAOSingleton.getInstance().findTorrentByChecksum(t.getChecksum()); mt.setMovieID(movie); mt.setTorrent(t); mt.setTorrentID(t.getId()); MovieTorrentDAO mtUpdater = new MovieTorrentDAO(mt); mtUpdater.start(); try { mtUpdater.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } t.setMovieTorrent(mt); torrentUpdater = new TorrentDAO(t); torrentUpdater.start(); try { torrentUpdater.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } Collection<MovieTorrent> movieTorrentCollection = movie.getMovieTorrentCollection(); if ((movieTorrentCollection == null) || (movieTorrentCollection.isEmpty())) { movieTorrentCollection = new ArrayList<>(); } movieTorrentCollection.add(mt); movie.setMovieTorrentCollection(movieTorrentCollection); MovieDAO movieUpdater = new MovieDAO(retrievedVideo, movie); movieUpdater.start(); try { movieUpdater.join(); } catch (InterruptedException ex) { Logger.getLogger(UpdaterForMovies.class.getName()).log(Level.SEVERE, null, ex); } this.completedSuccessfuly = true; } } }