List of usage examples for java.lang Thread getId
public long getId()
From source file:org.batoo.jpa.benchmark.BenchmarkTest.java
private ThreadPoolExecutor createExecutor(BlockingQueue<Runnable> workQueue) { final AtomicInteger nextThreadNo = new AtomicInteger(0); final ThreadPoolExecutor executor = new ThreadPoolExecutor(// BenchmarkTest.THREAD_COUNT, BenchmarkTest.THREAD_COUNT, // min max threads 0L, TimeUnit.MILLISECONDS, // the keep alive time - hold it forever workQueue, new ThreadFactory() { @Override//from ww w .j av a 2 s . c o m public Thread newThread(Runnable r) { final Thread t = new Thread(r); t.setDaemon(true); t.setPriority(Thread.NORM_PRIORITY); t.setName("Benchmark-" + nextThreadNo.get()); BenchmarkTest.this.threadIds[nextThreadNo.getAndIncrement()] = t.getId(); return t; } }); executor.prestartAllCoreThreads(); return executor; }
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;/*from w ww .j a va2 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; } } }
From source file:at.jku.rdfstats.RDFStatsUpdatableModelImpl.java
/** * /*from w ww .j a v a 2 s .c om*/ * @param ds * @param warnOnly if true, only log.warn(), otherwise throws exception * @throws RDFStatsModelException */ private void checkLock(RDFStatsDataset ds, boolean warnOnly) throws RDFStatsModelException { Thread prev = lockOwner(ds); String dsStr = (ds == null) ? "all statistics" : ds.toString(); if (prev == null) { String msg = "Unauthorized modification operation: Thread " + Thread.currentThread().getName() + " has no exclusive write lock for " + dsStr + "."; if (warnOnly) log.warn(msg); else throw new RDFStatsModelException(msg); } if (Thread.currentThread() != prev) { String msg = "Unauthorized modification operation: Thread " + Thread.currentThread().getName() + " has no exclusive write lock for " + dsStr + " (it is locked by Thread " + prev.getId() + "."; if (warnOnly) log.warn(msg); else throw new RDFStatsModelException(msg); } }
From source file:com.mirth.connect.donkey.server.channel.DestinationConnector.java
public void startQueue() { if (isQueueEnabled()) { // Remove any items in the queue's buffer because they may be outdated and refresh the queue size queue.invalidate(true, true);//from w w w. j a va 2s.c o m for (int i = 1; i <= destinationConnectorProperties.getThreadCount(); i++) { Thread thread = new Thread(this); thread.setName("Destination Queue Thread " + i + " on " + channel.getName() + " (" + getChannelId() + "), " + destinationName + " (" + getMetaDataId() + ")"); thread.start(); queueThreads.put(thread.getId(), thread); } } }
From source file:org.bonitasoft.engine.test.internal.EngineStarter.java
private boolean isExpectedThread(final Thread thread) { final String name = thread.getName(); final ThreadGroup threadGroup = thread.getThreadGroup(); if (threadGroup != null && threadGroup.getName().equals("system")) { return true; }/*from w ww .j a v a 2 s.c o m*/ final List<String> startWithFilter = Arrays.asList("H2 ", "Timer-0" /* postgres driver related */, "bitronix", "main", "Reference Handler", "Signal Dispatcher", "Finalizer", "com.google.common.base.internal.Finalizer", "process reaper", "ReaderThread", "Abandoned connection cleanup thread", "Monitor Ctrl-Break"/* Intellij */, "daemon-shutdown", "surefire-forkedjvm", "Restlet"); for (final String prefix : startWithFilter) { if (name.startsWith(prefix)) { return true; } } //shutdown hook not executed in main thread return thread.getId() == Thread.currentThread().getId(); }
From source file:org.sakaiproject.status.StatusServlet.java
protected void reportThreadStackTraces(HttpServletResponse response) throws Exception { PrintWriter pw = response.getWriter(); for (Thread thread : findAllThreads()) { if (thread != null) { String stackTrace = ""; try { StackTraceElement[] stack = thread.getStackTrace(); for (StackTraceElement ste : stack) { stackTrace += ste.getClassName() + "." + ste.getMethodName() + "();" + ste.getFileName() + ":" + ste.getLineNumber() + " "; }/*from w w w.j av a2 s . c o m*/ } catch (Exception e) { stackTrace += "-"; } pw.print(thread.getThreadGroup().getName() + " " + thread.getId() + " " + stackTrace + "\n"); } } }
From source file:org.deviceconnect.android.localoauth.LocalOAuth2Main.java
/** * (5)???./*from www. j a v a 2 s.co m*/ * <p> * - Activity?process?????Device Connect Manager?????<br> * - Device Connect Manager???????(0)onBind()?Bind?<br> * - Messenger, Handler ?LocalOAuth???<br> * * - ????<br> * * - (a)?????(?) => * ?????/??Bind??Service?Message??<br> * * - (b)???????? => * ?????/??Bind??Service?Message??<br> * * - (c)?????? => ???????(Message???)<br> * </p> * @param params * @param listener (???????????) * @throws AuthorizationException Authorization. */ public void confirmPublishAccessToken(final ConfirmAuthParams params, final PublishAccessTokenListener listener) throws AuthorizationException { if (params == null) { throw new IllegalArgumentException("confirmAuthParams is null."); } else if (listener == null) { throw new IllegalArgumentException("publishAccessTokenListener is null."); } else if (params.getContext() == null) { throw new IllegalArgumentException("Context is null."); } else if (params.getApplicationName() == null || params.getApplicationName().isEmpty()) { throw new IllegalArgumentException("ApplicationName is null."); } else if (params.getClientId() == null || params.getClientId().isEmpty()) { throw new IllegalArgumentException("ClientId is null."); } else if (params.getScopes() == null || params.getScopes().length <= 0) { throw new IllegalArgumentException("Scope is null."); } else if (!mDb.isOpen()) { throw new RuntimeException("Database is not opened."); } synchronized (mLockForDbAccess) { // ID? Thread thread = Thread.currentThread(); final long threadId = thread.getId(); // ?(???????("ja_JP")???????) String locale = Locale.getDefault().getLanguage(); String[] splitLocales = locale.split("_"); if (splitLocales.length > 1) { locale = splitLocales[0]; } // ????devicePlugin.xml??????? Map<String, DevicePluginXmlProfile> supportProfiles = null; if (params.isForDevicePlugin()) { supportProfiles = DevicePluginXmlUtil.getSupportProfiles(params.getContext(), params.getContext().getPackageName()); } String[] scopes = params.getScopes(); String[] displayScopes = new String[scopes.length]; for (int i = 0; i < scopes.length; i++) { // ?????? displayScopes[i] = ScopeUtil.getDisplayScope(params.getContext(), scopes[i], locale, supportProfiles); } // ?? ConfirmAuthRequest request = new ConfirmAuthRequest(threadId, params, listener, displayScopes, params.isAutoFlag()); // ? enqueueRequest(request); // Activity??Bind????????? // Activity? if (mRequestQueue.size() <= 1) { startConfirmAuthActivity(pickupRequest()); } } }
From source file:io.requery.android.database.sqlite.SQLiteConnectionPool.java
private void logConnectionPoolBusyLocked(long waitMillis, int connectionFlags) { final Thread thread = Thread.currentThread(); StringBuilder msg = new StringBuilder(); msg.append("The connection pool for database '").append(mConfiguration.label); msg.append("' has been unable to grant a connection to thread "); msg.append(thread.getId()).append(" (").append(thread.getName()).append(") "); msg.append("with flags 0x").append(Integer.toHexString(connectionFlags)); msg.append(" for ").append(waitMillis * 0.001f).append(" seconds.\n"); ArrayList<String> requests = new ArrayList<>(); int activeConnections = 0; int idleConnections = 0; if (!mAcquiredConnections.isEmpty()) { for (SQLiteConnection connection : mAcquiredConnections.keySet()) { String description = connection.describeCurrentOperationUnsafe(); if (description != null) { requests.add(description); activeConnections += 1;//from www . java 2 s . c o m } else { idleConnections += 1; } } } int availableConnections = mAvailableNonPrimaryConnections.size(); if (mAvailablePrimaryConnection != null) { availableConnections += 1; } msg.append("Connections: ").append(activeConnections).append(" active, "); msg.append(idleConnections).append(" idle, "); msg.append(availableConnections).append(" available.\n"); if (!requests.isEmpty()) { msg.append("\nRequests in progress:\n"); for (String request : requests) { msg.append(" ").append(request).append("\n"); } } Log.w(TAG, msg.toString()); }
From source file:org.terasoluna.gfw.common.exception.ResultMessagesLoggingInterceptorTest.java
/** * [invoke] Case of not occur exception in a multit-hreaded environment. * <p>//from w ww .ja v a 2 s . co m * [Expected Result] * <ol> * <li>method's return value is expected.</li> * <li>log is not output.</li> * </ol> * </p> */ @Test public void testInvoke_multi_thread_not_occur_exception() throws Throwable { // do setup for test case. final TestFacade facade = getApplicationContext().getBean(TestFacade.class); final Map<Thread, String> actualMessage = new HashMap<Thread, String>(); // setup for thread1. Thread thread1 = new Thread(new Runnable() { @Override public void run() { facade.setSleepTime(Long.valueOf(2)); actualMessage.put(Thread.currentThread(), facade.getMessage()); } }); // setup for thread2. Thread thread2 = new Thread(new Runnable() { @Override public void run() { facade.setSleepTime(Long.valueOf(0)); actualMessage.put(Thread.currentThread(), facade.getMessage()); } }); // do test. thread1.start(); TimeUnit.SECONDS.sleep(1); thread2.start(); // wait thread finish. thread1.join(); thread2.join(); // do assert. String expectedBaseMessage = getApplicationContext().getBean(TestRepository.class).toString() + ":"; assertThat(actualMessage.get(thread1), is(expectedBaseMessage + thread1.getId())); assertThat(actualMessage.get(thread2), is(expectedBaseMessage + thread2.getId())); verify(mockExceptionLogger, never()).warn((Exception) any()); }