List of usage examples for java.lang Thread join
public final void join() throws InterruptedException
From source file:com.sonicle.webtop.mail.MailAccount.java
public void loadFoldersCache(final Object lock, boolean waitLoad) throws MessagingException { Folder froot = getDefaultFolder();/* www . j a va 2s . com*/ fcRoot = createFolderCache(froot); fcRoot.setIsRoot(true); Folder children[] = fcRoot.getFolder().list(); final ArrayList<FolderCache> rootParents = new ArrayList<FolderCache>(); for (Folder child : children) { if (ms.isFolderHidden(this, child.getFullName())) continue; if (!fcRoot.hasChild(child.getName())) { FolderCache fcc = addSingleFoldersCache(fcRoot, child); if (!fcc.isStartupLeaf()) rootParents.add(fcc); } } if (hasDifferentDefaultFolder) { //check for other shared folders to be added Folder rfolders[] = store.getDefaultFolder().list(); for (int i = 0; i < sharedPrefixes.length; ++i) { for (int j = 0; j < rfolders.length; ++j) { if (rfolders[j].getFullName().equals(sharedPrefixes[i])) { FolderCache fcc = addSingleFoldersCache(fcRoot, rfolders[j]); rootParents.add(fcc); } } } } Thread engine = new Thread(new Runnable() { public void run() { synchronized (lock) { try { for (FolderCache fc : rootParents) { _loadFoldersCache(fc); } } catch (MessagingException exc) { Service.logger.error("Exception", exc); } } } }); engine.start(); try { if (waitLoad) engine.join(); } catch (InterruptedException exc) { Service.logger.error("Error waiting folder cache load", exc); } }
From source file:net.sourceforge.fenixedu.domain.accounting.report.events.EventReportQueueJob.java
private SheetData<ExemptionBean> allExemptions(final StringBuilder errors) { List<String> allEventsExternalIds = getAllEventsExternalIds(); logger.info(String.format("%s events (exemptions) to process", allEventsExternalIds.size())); Integer blockRead = 0;// www .j a v a 2 s. c o m final List<ExemptionBean> result = Collections.synchronizedList(new ArrayList<ExemptionBean>()); while (blockRead < allEventsExternalIds.size()) { Integer inc = BLOCK; if (blockRead + inc >= allEventsExternalIds.size()) { inc = allEventsExternalIds.size() - blockRead; } final List<String> block = allEventsExternalIds.subList(blockRead, blockRead + inc); blockRead += inc; Thread thread = new Thread() { @Override @Atomic(mode = TxMode.READ) public void run() { for (String oid : block) { Event event = FenixFramework.getDomainObject(oid); try { if (!isAccountingEventForReport(event)) { continue; } result.addAll(writeExemptionInformation(event)); } catch (Throwable e) { errors.append(getErrorLine(event, e)); } } } }; thread.start(); try { thread.join(); } catch (InterruptedException e) { } logger.info(String.format("Read %s events", blockRead)); } return new SheetData<ExemptionBean>(result) { @Override protected void makeLine(ExemptionBean bean) { addCell("Identificador", bean.eventExternalId); addCell("Tipo da Iseno", bean.exemptionTypeDescription); addCell("Valor da Iseno", bean.exemptionValue); addCell("Percentagem da Iseno", bean.percentage); addCell("Motivo da Iseno", bean.justification); } }; }
From source file:net.sourceforge.fenixedu.domain.accounting.report.events.EventReportQueueJob.java
private SheetData<AccountingTransactionBean> allTransactions(final StringBuilder errors) { List<String> allEventsExternalIds = getAllEventsExternalIds(); logger.info(String.format("%s events (transactions) to process", allEventsExternalIds.size())); Integer blockRead = 0;//from w w w . j av a2s. c o m final List<AccountingTransactionBean> result = Collections .synchronizedList(new ArrayList<AccountingTransactionBean>()); while (blockRead < allEventsExternalIds.size()) { Integer inc = BLOCK; if (blockRead + inc >= allEventsExternalIds.size()) { inc = allEventsExternalIds.size() - blockRead; } final List<String> block = allEventsExternalIds.subList(blockRead, blockRead + inc); blockRead += inc; Thread thread = new Thread() { @Override @Atomic(mode = TxMode.READ) public void run() { for (String oid : block) { Event event = FenixFramework.getDomainObject(oid); try { if (!isAccountingEventForReport(event)) { continue; } result.addAll(writeTransactionInformation(event)); } catch (Throwable e) { errors.append(getErrorLine(event, e)); } } } }; thread.start(); try { thread.join(); } catch (InterruptedException e) { } logger.info(String.format("Read %s events", blockRead)); } return new SheetData<AccountingTransactionBean>(result) { @Override protected void makeLine(AccountingTransactionBean bean) { addCell("Identificador", bean.eventExternalId); addCell("Data do pagamento", bean.whenRegistered); addCell("Data de entrada do pagamento", bean.whenProcessed); addCell("Nome da entidade devedora", bean.debtPartyName); addCell("Contribuinte da entidade devedora", bean.debtSocialSecurityNumber); addCell("Nome da entidade credora", bean.credPartyName); addCell("Contribuinte da entidade credora", bean.credSocialSecurityNumber); addCell("Montante inicial", bean.originalAmount); addCell("Montante ajustado", bean.amountWithAdjustment); addCell("Modo de pagamento", bean.paymentMode); addCell("Data do ajuste", bean.whenAdjustmentRegistered); addCell("Data de entrada do ajuste", bean.whenAdjustmentProcessed); addCell("Montante do ajuste", bean.adjustmentAmount); addCell("Justificao", bean.comments); } }; }
From source file:org.terasoluna.gfw.common.exception.ResultMessagesLoggingInterceptorTest.java
/** * [invoke] Case of occur BusinessException on both thread in a multit-hreaded environment. * <p>/* w w w. j a v a 2s. com*/ * [Expected Result] * <ol> * <li>throws BusinessException on both thread.</li> * <li>BusinessException log is output & not duplicate on both thread.</li> * <li>unnecessary log is not output.</li> * </ol> * </p> */ @Test public void testInvoke_multi_thread_occur_businessexception_both_thread() throws Throwable { // do setup for test case. final TestFacade facade = getApplicationContext().getBean(TestFacade.class); final TestService service = getApplicationContext().getBean(TestService.class); final Map<Thread, BusinessException> actualBusinessException = new HashMap<Thread, BusinessException>(); // setup for thread1. final BusinessException occurExceptionForThread1 = new BusinessException( ResultMessages.error().add("e.cm.thread1")); Thread thread1 = new Thread(new Runnable() { @Override public void run() { service.setResultMessagesNotificationException(occurExceptionForThread1); facade.setSleepTime(Long.valueOf(2)); try { facade.getMessage(); } catch (BusinessException e) { actualBusinessException.put(Thread.currentThread(), e); } } }); // setup for thread2. final BusinessException occurExceptionForThread2 = new BusinessException( ResultMessages.error().add("e.cm.thread2")); Thread thread2 = new Thread(new Runnable() { @Override public void run() { service.setResultMessagesNotificationException(occurExceptionForThread2); facade.setSleepTime(Long.valueOf(0)); try { facade.getMessage(); } catch (BusinessException e) { actualBusinessException.put(Thread.currentThread(), e); } } }); // do test. thread1.start(); TimeUnit.SECONDS.sleep(1); thread2.start(); // wait thread finish. thread1.join(); thread2.join(); // do assert assertThat(actualBusinessException.get(thread1), is(occurExceptionForThread1)); assertThat(actualBusinessException.get(thread2), is(occurExceptionForThread2)); verify(mockExceptionLogger, times(1)).warn(occurExceptionForThread1); verify(mockExceptionLogger, times(1)).warn(occurExceptionForThread2); verify(mockExceptionLogger, times(2)).warn((Exception) anyObject()); }
From source file:eu.stratosphere.pact.runtime.task.MatchTaskTest.java
@Test public void testCancelMatchTaskWhileSort1() { int keyCnt = 20; int valCnt = 20; super.initEnvironment(6 * 1024 * 1024); super.addInput(new DelayingInfinitiveInputIterator(100), 1); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 2); super.addOutput(new NirvanaOutputList()); final MatchTask<PactRecord, PactRecord, PactRecord> testTask = new MatchTask<PactRecord, PactRecord, PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.SORT_BOTH_MERGE); super.getTaskConfig().setMemorySize(6 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(4); final int[] keyPos1 = new int[] { 0 }; final int[] keyPos2 = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos1, keyClasses); PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(1), keyPos2, keyClasses); super.registerTask(testTask, MockMatchStub.class); Thread taskRunner = new Thread() { @Override/*from w w w . j av a 2s . com*/ public void run() { try { testTask.invoke(); } catch (Exception ie) { ie.printStackTrace(); Assert.fail("Task threw exception although it was properly canceled"); } } }; taskRunner.start(); TaskCancelThread tct = new TaskCancelThread(1, taskRunner, testTask); tct.start(); try { tct.join(); taskRunner.join(); } catch (InterruptedException ie) { Assert.fail("Joining threads failed"); } }
From source file:eu.stratosphere.pact.runtime.task.MatchTaskTest.java
@Test public void testCancelMatchTaskWhileSort2() { int keyCnt = 20; int valCnt = 20; super.initEnvironment(6 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1); super.addInput(new DelayingInfinitiveInputIterator(100), 2); super.addOutput(new NirvanaOutputList()); final MatchTask<PactRecord, PactRecord, PactRecord> testTask = new MatchTask<PactRecord, PactRecord, PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.SORT_BOTH_MERGE); super.getTaskConfig().setMemorySize(6 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(4); final int[] keyPos1 = new int[] { 0 }; final int[] keyPos2 = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos1, keyClasses); PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(1), keyPos2, keyClasses); super.registerTask(testTask, MockMatchStub.class); Thread taskRunner = new Thread() { @Override/*www. j a v a 2 s . c om*/ public void run() { try { testTask.invoke(); } catch (Exception ie) { ie.printStackTrace(); Assert.fail("Task threw exception although it was properly canceled"); } } }; taskRunner.start(); TaskCancelThread tct = new TaskCancelThread(1, taskRunner, testTask); tct.start(); try { tct.join(); taskRunner.join(); } catch (InterruptedException ie) { Assert.fail("Joining threads failed"); } }
From source file:eu.stratosphere.pact.runtime.task.MatchTaskTest.java
@Test public void testCancelHashMatchTaskWhileBuildFirst() { int keyCnt = 20; int valCnt = 20; super.initEnvironment(6 * 1024 * 1024); super.addInput(new DelayingInfinitiveInputIterator(100), 1); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 2); super.addOutput(new NirvanaOutputList()); final MatchTask<PactRecord, PactRecord, PactRecord> testTask = new MatchTask<PactRecord, PactRecord, PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.HYBRIDHASH_FIRST); super.getTaskConfig().setMemorySize(6 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(4); final int[] keyPos1 = new int[] { 0 }; final int[] keyPos2 = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos1, keyClasses); PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(1), keyPos2, keyClasses); super.registerTask(testTask, MockMatchStub.class); Thread taskRunner = new Thread() { @Override//from w ww .j a va2 s . c o m public void run() { try { testTask.invoke(); } catch (Exception ie) { ie.printStackTrace(); Assert.fail("Task threw exception although it was properly canceled"); } } }; taskRunner.start(); TaskCancelThread tct = new TaskCancelThread(1, taskRunner, testTask); tct.start(); try { tct.join(); taskRunner.join(); } catch (InterruptedException ie) { Assert.fail("Joining threads failed"); } }
From source file:eu.stratosphere.pact.runtime.task.MatchTaskTest.java
@Test public void testHashCancelMatchTaskWhileBuildSecond() { int keyCnt = 20; int valCnt = 20; super.initEnvironment(6 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1); super.addInput(new DelayingInfinitiveInputIterator(100), 2); super.addOutput(new NirvanaOutputList()); final MatchTask<PactRecord, PactRecord, PactRecord> testTask = new MatchTask<PactRecord, PactRecord, PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.HYBRIDHASH_SECOND); super.getTaskConfig().setMemorySize(6 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(4); final int[] keyPos1 = new int[] { 0 }; final int[] keyPos2 = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos1, keyClasses); PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(1), keyPos2, keyClasses); super.registerTask(testTask, MockMatchStub.class); Thread taskRunner = new Thread() { @Override/*w ww. j a va2 s . com*/ public void run() { try { testTask.invoke(); } catch (Exception ie) { ie.printStackTrace(); Assert.fail("Task threw exception although it was properly canceled"); } } }; taskRunner.start(); TaskCancelThread tct = new TaskCancelThread(1, taskRunner, testTask); tct.start(); try { tct.join(); taskRunner.join(); } catch (InterruptedException ie) { Assert.fail("Joining threads failed"); } }
From source file:eu.stratosphere.pact.runtime.task.MatchTaskTest.java
@Test public void testCancelMatchTaskWhileMatching() { int keyCnt = 20; int valCnt = 20; super.initEnvironment(6 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 2); super.addOutput(new NirvanaOutputList()); final MatchTask<PactRecord, PactRecord, PactRecord> testTask = new MatchTask<PactRecord, PactRecord, PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.SORT_BOTH_MERGE); super.getTaskConfig().setMemorySize(6 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(4); final int[] keyPos1 = new int[] { 0 }; final int[] keyPos2 = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos1, keyClasses); PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(1), keyPos2, keyClasses); super.registerTask(testTask, MockDelayingMatchStub.class); Thread taskRunner = new Thread() { @Override/*from ww w. ja v a 2 s.c om*/ public void run() { try { testTask.invoke(); } catch (Exception ie) { ie.printStackTrace(); Assert.fail("Task threw exception although it was properly canceled"); } } }; taskRunner.start(); TaskCancelThread tct = new TaskCancelThread(1, taskRunner, testTask); tct.start(); try { tct.join(); taskRunner.join(); } catch (InterruptedException ie) { Assert.fail("Joining threads failed"); } }
From source file:eu.stratosphere.pact.runtime.task.MatchTaskTest.java
@Test public void testHashFirstCancelMatchTaskWhileMatching() { int keyCnt = 20; int valCnt = 20; super.initEnvironment(6 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 2); super.addOutput(new NirvanaOutputList()); final MatchTask<PactRecord, PactRecord, PactRecord> testTask = new MatchTask<PactRecord, PactRecord, PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.HYBRIDHASH_FIRST); super.getTaskConfig().setMemorySize(6 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(4); final int[] keyPos1 = new int[] { 0 }; final int[] keyPos2 = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos1, keyClasses); PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(1), keyPos2, keyClasses); super.registerTask(testTask, MockDelayingMatchStub.class); Thread taskRunner = new Thread() { @Override// ww w . j a v a2s . com public void run() { try { testTask.invoke(); } catch (Exception ie) { ie.printStackTrace(); Assert.fail("Task threw exception although it was properly canceled"); } } }; taskRunner.start(); TaskCancelThread tct = new TaskCancelThread(1, taskRunner, testTask); tct.start(); try { tct.join(); taskRunner.join(); } catch (InterruptedException ie) { Assert.fail("Joining threads failed"); } }