List of usage examples for java.lang Object wait
public final void wait() throws InterruptedException
From source file:core.sample.pool.PoolWorker.java
public void run() { try {/*from w w w . ja va2s . c om*/ // log.debug("**** Running Tester Thread = " + id); WorkerThread rt1 = (WorkerThread) pool.borrowObject(); Object synObj = new Object(); Object[] params = new Object[] { "Hello", new Integer(id) }; Class[] parmTypes = new Class[] { String.class, int.class }; rt1.execute("com.findonnet.services.pooling.test.SampleWork", "executeTask", params, parmTypes, synObj); // rt1.execute("com.findonnet.services.pooling.test.SampleWork", // "executeTask", null, null, synObj); synchronized (synObj) { synObj.wait(); } pool.returnObject(rt1); // log.debug("*** Finished Thread " + id); } catch (Exception e) { log.error("", e); } }
From source file:com.devbury.desktoplib.systemtray.SystemTrayApplication.java
public void start() { logSystemInfo();//from w w w .j a v a 2 s. co m try { if (!isSystemTraySupported()) { JOptionPane.showMessageDialog(null, "Could not start application. This application requires system tray support and your platform " + "does not provide this.", "System Tray Not Supported", JOptionPane.ERROR_MESSAGE); throw new RuntimeException("SystemTray is not supported"); } else { logger.debug("SystemTray is supported"); } if (applicationContext == null) { String[] locations = buildConfigLocations(); logger.debug("Creating context from " + configLocationsToString(locations)); applicationContext = new ClassPathXmlApplicationContext(locations); logger.debug("Context finished building"); } // get the TrayIconDefinition instances Map defs = applicationContext.getBeansOfType(TrayIconDefinition.class); if (defs == null || defs.isEmpty()) { throw new RuntimeException("No TrayIconDefinition instances exist in the context"); } SystemTray tray = newSystemTray(); Iterator<TrayIconDefinition> it = defs.values().iterator(); LinkedList<TrayIcon> installedIcons = new LinkedList<TrayIcon>(); while (it.hasNext()) { TrayIconDefinition def = (TrayIconDefinition) it.next(); try { TrayIcon ti = def.buildTrayIcon(); tray.add(ti); installedIcons.add(ti); } catch (Throwable t) { logger.error("Could not add TrayIconDefinition " + def); } } // get the monitor object out of the context to block on Object monitor = applicationContext.getBean("applicationShutdownService"); // if there was a splash screen shut it down SplashScreen splash = newSplashScreen(); if (splash != null) { logger.debug("Shutting down splash screen"); splash.close(); } synchronized (monitor) { monitor.wait(); } logger.debug("Application shutting down"); Iterator<TrayIcon> trayIconIt = installedIcons.iterator(); while (trayIconIt.hasNext()) { TrayIcon ti = (TrayIcon) trayIconIt.next(); tray.remove(ti); } applicationContext.close(); logger.debug("Application stopped"); } catch (Throwable t) { logger.error("Unresolved exception", t); logger.error("Application shutting down"); if (applicationContext != null) { applicationContext.close(); } logger.error("Application stopped"); } }
From source file:org.cloudgraph.hbase.graph.ParallelSubgraphTask.java
/** * Assembles a given set of edges where the target is a different row, within * this table or another. Since we are assembling a graph, and each edge links * another row, each edge requires a new row reader. * /*from ww w .j a v a 2 s.c o m*/ * @param target * the object source to which we link edges * @param prop * the edge property * @param edges * the edges * @param rowReader * the row reader * @param childTableReader * the table reader for the child objects * @param level * the assembly level * @throws IOException */ protected void assembleExternalEdges(PlasmaDataObject target, long targetSequence, PlasmaProperty prop, EdgeReader collection, RowReader rowReader, TableReader childTableReader, int level) throws IOException { for (CellValues childValues : collection.getRowValues()) { // see if this row is locked during fetch, and wait for it Object rowLock = fetchLocks.get(Arrays.hashCode(childValues.getRowKey())); if (rowLock != null) { synchronized (rowLock) { try { rowLock.wait(); } catch (InterruptedException e) { log.error(e.getMessage(), e); } } } RowReader existingChildRowReader = childTableReader.getRowReader(childValues.getRowKey()); if (existingChildRowReader != null) { // If assembled this row root before, // just link it. The data is already complete. PlasmaDataObject existingChild = (PlasmaDataObject) existingChildRowReader.getRootDataObject(); synchronized (existingChild) { synchronized (target) { link(existingChild, target, prop); } } continue; } // While fetching this node, another thread can fail to find an // existing row reader registered // above and fall through to this fetch, and therefore fetch the // same row, in addition // to attempting to create the same row reader below, causing an // error or warning // The second thread may be arriving at this node from another // property/edge and // therefore need to link from another edge above. fetchLocks.put(Arrays.hashCode(childValues.getRowKey()), new Object()); this.assembleExternalEdge(childValues, collection, childTableReader, target, targetSequence, prop, level); rowLock = fetchLocks.remove(Arrays.hashCode(childValues.getRowKey())); if (rowLock != null) { synchronized (rowLock) { rowLock.notifyAll(); } } else { log.error("expected locked row key '" + Bytes.toString(childValues.getRowKey()) + "' for edgeReader, " + collection); } } }
From source file:org.cloudgraph.hbase.graph.ParallelSliceSubgraphTask.java
/** * Assembles a given set of edges where the target is a different row, within * this table or another. Since we are assembling a graph, each edge requires * a new row reader. Each edge is a new root in the target table so need a new * row reader for each.//from w w w . jav a 2s. c o m * * @param target * the object source to which we link edges * @param prop * the edge property * @param edges * the edges * @param rowReader * the row reader * @param childTableReader * the table reader for the child objects * @param level * the assembly level * @throws IOException */ protected void assembleExternalEdges(PlasmaDataObject target, long targetSequence, PlasmaProperty prop, EdgeReader collection, RowReader rowReader, List<CellValues> resultRows, TableReader childTableReader, int level) throws IOException { for (CellValues childValues : resultRows) { CellValues childResult = null; if (resultRows != null && !resultRows.contains(Arrays.hashCode(childValues.getRowKey()))) continue; // not found in predicate // see if this row is locked during fetch, and wait for it Object rowLock = fetchLocks.get(Arrays.hashCode(childValues.getRowKey())); if (rowLock != null) { synchronized (rowLock) { try { rowLock.wait(); } catch (InterruptedException e) { log.error(e.getMessage(), e); } } } RowReader existingChildRowReader = childTableReader.getRowReader(childValues.getRowKey()); if (existingChildRowReader != null) { // If assembled this row root before, // just link it. The data is already complete. PlasmaDataObject existingChild = (PlasmaDataObject) existingChildRowReader.getRootDataObject(); synchronized (existingChild) { synchronized (target) { link(existingChild, target, prop); } } continue; } // While fetching this node, another thread can fail to find an // existing row reader registered // above and fall through to this fetch, and therefore fetch the // same row, in addition // to attempting to create the same row reader below, causing an // error or warning // The second thread may be arriving at this node from another // property/edge and // therefore need to link from another edge above. fetchLocks.put(Arrays.hashCode(childValues.getRowKey()), new Object()); if (log.isDebugEnabled()) log.debug("fetch external row: " + prop.toString() + " (" + childValues.getRowKey() + ")"); childResult = fetchGraph(childValues.getRowKey(), childTableReader, collection.getBaseType()); if (childResult.containsColumn(rootTableReader.getTableConfig().getDataColumnFamilyNameBytes(), GraphMetaKey.TOMBSTONE.codeAsBytes())) { log.warn("ignoring toubstone result row '" + childValues.getRowKey() + "'"); continue; // ignore toumbstone edge } PlasmaType subType = collection.getSubType(); if (subType == null) subType = collection.getBaseType(); GraphColumnKeyFactory keyFactory = this.getKeyFactory(subType); byte[] uuidQual = keyFactory.createColumnKey(subType, EntityMetaKey.UUID); // need to reconstruct the original graph, so need original UUID byte[] rootUuid = childResult.getColumnValue( Bytes.toBytes(childTableReader.getTableConfig().getDataColumnFamilyName()), uuidQual); if (rootUuid == null) throw new GraphServiceException( "expected column: " + childTableReader.getTableConfig().getDataColumnFamilyName() + ":" + Bytes.toString(uuidQual)); String uuidStr = null; uuidStr = new String(rootUuid, childTableReader.getTableConfig().getCharset()); UUID uuid = UUID.fromString(uuidStr); PlasmaDataObject child = null; synchronized (target) { // create a child object using UUID from external row root child = createChild(source, sourceProperty, uuid, collection.getBaseType()); } RowReader childRowReader = null; synchronized (childTableReader) { // create a row reader for every external edge childRowReader = childTableReader.createRowReader(child, childResult); } synchronized (this.distributedReader) { this.distributedReader.mapRowReader(childValues.getRowKey(), childRowReader); } synchronized (target) { childRowReader.addDataObject(child); } // FIXME: we have the child already why is the sequence needed traversals.add(new Traversal(child, -1, collection, target, prop, childRowReader, true, level + 1)); rowLock = fetchLocks.remove(Arrays.hashCode(childValues.getRowKey())); synchronized (rowLock) { rowLock.notifyAll(); } } }
From source file:test.integ.be.fedict.commons.eid.client.BeIDCardManagerTest.java
@Test public void testListenerModification() throws Exception { final TestLogger logger = new TestLogger(); final BeIDCardManager beIDCardManager = new BeIDCardManager(logger); beIDCardManager.setLocale(Locale.FRENCH); final Object waitObject = new Object(); beIDCardManager/* w w w . j a va2 s . c o m*/ .addBeIDCardEventListener(new BeIDCardEventsTestListener(beIDCardManager, waitObject, true, false)); beIDCardManager.addBeIDCardEventListener( new BeIDCardEventsTestListener(beIDCardManager, waitObject, false, false)); beIDCardManager .addBeIDCardEventListener(new BeIDCardEventsTestListener(beIDCardManager, waitObject, false, true)); beIDCardManager.start(); synchronized (waitObject) { waitObject.wait(); } }
From source file:test.integ.be.fedict.commons.eid.client.BeIDCardManagerTest.java
@Test public void testExceptionsInListener() throws Exception { final TestLogger logger = new TestLogger(); final BeIDCardManager beIDCardManager = new BeIDCardManager(logger); beIDCardManager.setLocale(Locale.GERMAN); final Object waitObject = new Object(); beIDCardManager/*from ww w. j a va 2 s . co m*/ .addBeIDCardEventListener(new BeIDCardEventsTestListener(beIDCardManager, waitObject, true, false)); beIDCardManager.addBeIDCardEventListener( new BeIDCardEventsTestListener(beIDCardManager, waitObject, false, false)); beIDCardManager .addBeIDCardEventListener(new BeIDCardEventsTestListener(beIDCardManager, waitObject, false, true)); beIDCardManager.start(); synchronized (waitObject) { waitObject.wait(); } }
From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java
/** * Returns a directory where the given version of the Cordova Plugin * can be installed from. This method downloads the given * cordova plugin if necessary.// w w w. j a va 2 s . c o m * * @param plugin * @return */ public File getInstallationDirectory(RegistryPluginVersion plugin, IProgressMonitor monitor) { if (monitor == null) monitor = new NullProgressMonitor(); File pluginDir = getFromCache(plugin); if (pluginDir != null) { return pluginDir; } File newCacheDir = calculateCacheDir(plugin); IRetrieveFileTransfer transfer = HybridCore.getDefault().getFileTransferService(); IFileID remoteFileID; try { remoteFileID = FileIDFactory.getDefault().createFileID(transfer.getRetrieveNamespace(), plugin.getTarball()); Object lock = new Object(); PluginReceiver receiver = new PluginReceiver(newCacheDir, monitor, lock); synchronized (lock) { transfer.sendRetrieveRequest(remoteFileID, receiver, null); lock.wait(); } } catch (FileCreateException e) { HybridCore.log(IStatus.ERROR, "Cordova plugin fetch error", e); } catch (IncomingFileTransferException e) { HybridCore.log(IStatus.ERROR, "Cordova plugin fetch error", e); } catch (InterruptedException e) { HybridCore.log(IStatus.ERROR, "Cordova plugin fetch error", e); } return new File(newCacheDir, "package"); }
From source file:it.osm.gtfs.GTFSOSMImport.java
@Command(description = "Analyze the diff between osm relations and gtfs trips") public void reldiffx() throws IOException, ParserConfigurationException, SAXException { final Object lock = new Object(); final GTFSRouteDiffGui app = new GTFSRouteDiffGui(); app.setVisible(true);/*from w ww . j ava 2 s . c o m*/ app.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { synchronized (lock) { app.setVisible(false); lock.notify(); } } }); synchronized (lock) { while (app.isVisible()) try { lock.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } app.dispose(); System.out.println("Done"); }
From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java
/** * Returns a directory where the given version of the Cordova Plugin * can be installed from. This method downloads the given * cordova plugin if necessary.//from ww w . jav a 2 s . co m * * @param plugin * @return */ public File getInstallationDirectory(CordovaRegistryPluginVersion plugin, IProgressMonitor monitor) { if (monitor == null) monitor = new NullProgressMonitor(); File pluginDir = getFromCache(plugin); if (pluginDir != null) { return pluginDir; } File newCacheDir = calculateCacheDir(plugin); IRetrieveFileTransfer transfer = HybridCore.getDefault().getFileTransferService(); IFileID remoteFileID; try { remoteFileID = FileIDFactory.getDefault().createFileID(transfer.getRetrieveNamespace(), plugin.getDistributionTarball()); Object lock = new Object(); PluginReceiver receiver = new PluginReceiver(newCacheDir, monitor, lock); synchronized (lock) { transfer.sendRetrieveRequest(remoteFileID, receiver, null); lock.wait(); } } catch (FileCreateException e) { HybridCore.log(IStatus.ERROR, "Cordova plugin fetch error", e); } catch (IncomingFileTransferException e) { HybridCore.log(IStatus.ERROR, "Cordova plugin fetch error", e); } catch (InterruptedException e) { HybridCore.log(IStatus.ERROR, "Cordova plugin fetch error", e); } updateDownlodCounter(plugin.getName()); return new File(newCacheDir, "package"); }
From source file:org.paxle.crawler.LimitedRateCopierTest.java
public void testThreadedCopy() throws Exception { // FIXME if size is in the order of magnitude of limitKBps, this test works, but ... final int size = 1024 * 4; // ... try to increase this value ... final int threadNum = 4; final int limitKBps = 8; // ... and this one proportionally, and watch how it explodes :) final int expectedTime = size / 1024 * 1000 / limitKBps * threadNum; final ILimitedRateCopier lrc = null; // new LimitedRateCopier(limitKBps); // System.out.println("expected time: " + expectedTime + " ms"); final ArrayList<Thread> threads = new ArrayList<Thread>(); final Object sync = new Object(); for (int i = 0; i < threadNum; i++) { final int num = i; final InputStream zis = new NullInputStream(size); final OutputStream nos = new NullOutputStream(); threads.add(new Thread() { {//from w ww . ja va2 s.co m this.setName("Test-thread " + num); } @Override public void run() { try { // System.out.println("thread " + num + " syncing"); synchronized (sync) { sync.wait(); } // System.out.println("thread " + num + " starts copying"); final long start = System.currentTimeMillis(); // lrc.copy(zis, nos, size); final long end = System.currentTimeMillis(); /* XXX this is wrong, because every new thread gets less bandwidth One would have to pre-set the * number of expected threads in the lrc for this to be correct assertTrue( String.format("%d: Threaded copying took %d ms but should have taken %d ms.", num, end - start, expectedTime), expectedTime <= end - start); */ // System.out.println("thread " + num + " finished in " + (end - start) + " ms"); } catch (Throwable e) { e.printStackTrace(); } } }); } for (final Thread t : threads) t.start(); Thread.sleep(10); // wait until all have started and are waiting on sync // System.out.println("notifying all"); final long start = System.currentTimeMillis(); synchronized (sync) { sync.notifyAll(); } for (final Thread t : threads) t.join(); final long end = System.currentTimeMillis(); // System.out.println(String.format("Finished in %d ms", end - start)); // assertTrue(String.format("All %d threads took %d ms but should have taken %d ms.", threadNum, end - start, expectedTime), // expectedTime <= end - start); }