List of usage examples for java.lang Runnable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:ch.sourcepond.utils.mdcwrapper.impl.DefaultMdcWrapper.java
@Override public Runnable wrap(final Runnable pRunnable) { notNull(pRunnable, "Runnable to be wrapped is null!"); // If the object is already a MDC-aware wrapper simply return it. if (MdcAwareRunnable.class.equals(pRunnable.getClass())) { return pRunnable; }//from w ww . j a v a2s . c o m return new MdcAwareRunnable(pRunnable); }
From source file:org.rhq.core.pc.availability.AvailabilityCollectorThreadPool.java
/** * Given a {@link AvailabilityCollectorRunnable} instance, this will run that instance in a thread, thus * allowing the availability status for a managed resource to be periodically checked asynchronously. The * given runnable will store its last known availability status so it can be retrieved very fast. * /*from ww w . j a v a 2s.c o m*/ * The given runnable must be of type {@link AvailabilityCollectorRunnable}, otherwise a runtime exception will occur. * * @param runnable the availability collector runnable that will be invoked in a thread to being collecting * availability status of a managed resource. */ public void execute(Runnable runnable) { if (runnable instanceof AvailabilityCollectorRunnable) { synchronized (this) { if (threadPool != null) { threadPool.execute(runnable); } } return; } else if (runnable == null) { throw new NullPointerException("runnable == null"); } else { throw new IllegalArgumentException("Runnable is of type [" + runnable.getClass() + "]; must be of type [" + AvailabilityCollectorRunnable.class + "]"); } }
From source file:com.icesoft.util.ThreadFactory.java
public Thread newThread(final Runnable runnable) { Thread _thread;/*from ww w. ja v a2 s . com*/ synchronized (lock) { _thread = new Thread(runnable, prefix + " [" + ++counter + "]"); } _thread.setDaemon(daemon); try { /* * We attempt to set the context class loader because some J2EE * containers don't seem to set this properly, which leads to * important classes not being found. However, other J2EE containers * see this as a security violation. */ _thread.setContextClassLoader(runnable.getClass().getClassLoader()); } catch (SecurityException exception) { /* * If the current security policy does not allow this, we have to * hope that the appropriate class loader settings were transferred * to this new thread. */ if (LOG.isTraceEnabled()) { LOG.trace("Setting the context class loader is not permitted.", exception); } } if (LOG.isDebugEnabled()) { LOG.debug("New thread: " + _thread.getName()); } return _thread; }
From source file:org.wings.session.LowLevelEventDispatcher.java
void invokeRunnables() { synchronized (this.runnables) { for (Iterator iterator = runnables.iterator(); iterator.hasNext();) { Runnable runnable = null; try { runnable = (Runnable) iterator.next(); try { runnable.run();/*w ww . j av a2 s .c o m*/ } catch (Throwable e) { log.error(runnable, e); } iterator.remove(); } catch (ConcurrentModificationException e) { throw new RuntimeException("Runnable class: " + runnable.getClass().getName(), e); } } } }
From source file:com.meltmedia.cadmium.servlets.guice.CadmiumListener.java
@Override public void contextDestroyed(ServletContextEvent event) { Set<Class<? extends Closeable>> closed = new HashSet<Class<? extends Closeable>>(); Injector injector = this.injector; if (jsr250Executor != null) { jsr250Executor.preDestroy(); jsr250Executor = null;// www .jav a 2 s . c o m } Set<Object> singletons = Jsr250Utils.findInstancesInScopes(injector, Singleton.class); Set<Object> otherSingletons = Jsr250Utils.findInstancesInScopes(injector, Scopes.SINGLETON); closeAll(closed, singletons); closeAll(closed, otherSingletons); closed.clear(); if (executor != null) { try { executor.shutdown(); } catch (Throwable t) { } try { if (!executor.awaitTermination(10, TimeUnit.SECONDS)) { log.warn("Thread pool executor did not terminate after 10 seconds, forcing shutdown."); for (Runnable terminated : executor.shutdownNow()) { log.warn("Terminated task of type {}.", terminated.getClass().getName()); } } } catch (Throwable t) { log.warn("Throwable thrown while terminating thread pool executor.", t); } } injector = null; executor = null; members.clear(); members = null; configManager = null; context = null; reflections = null; super.contextDestroyed(event); }
From source file:org.schedulesdirect.grabber.Grabber.java
private ThreadPoolExecutor createThreadPoolExecutor() { return new ThreadPoolExecutor(0, globalOpts.getMaxThreads(), 10, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadPoolExecutor.CallerRunsPolicy()) { @Override//from w w w. j a v a2 s . co m protected void afterExecute(Runnable r, Throwable t) { //super.afterExecute(r, t); if (t != null) { Logger log = Logger.getLogger(r.getClass()); log.error("Task failed!", t); if (!(r instanceof LogoTask)) failedTask = true; } } }; }
From source file:io.tilt.minka.business.impl.CoordinatorImpl.java
private void stop(final Synchronized synchro, final boolean withFire) { Validate.notNull(synchro);//w w w . j a va2s . c o m final Callable<?> callable = this.callablesBySynchro.get(synchro); final Runnable runnable = this.runnablesBySynchro.get(synchro); ScheduledFuture<?> future = this.futuresBySynchro.get(synchro); boolean dequeued = false; if (runnable != null) { runnablesBySynchro.remove(synchro); dequeued = this.executor.remove(runnable); } else if (callable != null) { callablesBySynchro.remove(synchro); } else { logger.error("{}: ({}) Runnable/Callable {} not found, finished or never scheduled", getClass().getSimpleName(), shardId, synchro.getAction().name()); return; } if (future != null) { boolean cancelled = future.cancel(withFire); logger.debug("{}: ({}) Stopping - Task {} ({}) Cancelled = {}, Dequeued = {}", getClass().getSimpleName(), shardId, synchro.getAction().name(), runnable.getClass().getSimpleName(), cancelled, dequeued); } else { logger.error("{}: ({}) Stopping - Task {} ({}) Not found !!", getClass().getSimpleName(), shardId, synchro.getAction().name(), runnable.getClass().getSimpleName()); } this.executor.purge(); agentsByAction.remove(synchro.getAction()); }
From source file:mfi.filejuggler.responsibles.BasicApplication.java
@Responsible(conditions = { Condition.SYS_SYSTEM_INFO, Condition.SYS_EXECUTE_JOB }) public void fjSystemInfo(StringBuilder sb, Map<String, String> parameters, Model model) throws Exception { if (model.lookupConversation().getCondition().equals(Condition.SYS_EXECUTE_JOB)) { String executeJob = StringUtils.trimToEmpty(parameters.get("execute_job")); for (String schedulerName : CronSchedulers.getInstance().getSchedulersIDs().keySet()) { if (StringUtils.equalsIgnoreCase(schedulerName, executeJob)) { Runnable r = CronSchedulers.getInstance().getSchedulersInstances().get(schedulerName); r.run();/*from w w w . j av a2 s. co m*/ model.lookupConversation().getMeldungen().add(r.getClass().getName() + " wurde gestartet"); break; } } } String warfilename = KVMemoryMap.getInstance().readValueFromKey("application.warfile"); String builddate = KVMemoryMap.getInstance().readValueFromKey("application.builddate"); if (warfilename == null) { warfilename = "Development Version"; } if (builddate == null) { builddate = "n/v"; } ButtonBar buttonBar = new ButtonBar(); buttonBar.getButtons().add(new Button("Reload", Condition.SYS_SYSTEM_INFO)); sb.append(HTMLUtils.buildMenuNar(model, "Systeminformationen", Condition.FS_NAVIGATE, buttonBar, false)); String attributeLeftCol = model.isPhone() ? HTMLUtils.buildAttribute("width", "40%") : null; HTMLTable table = new HTMLTable(); table.addTD("Anwendungsvariablen:", 2, HTMLTable.TABLE_HEADER); table.addNewRow(); table.addTD("Build:", 1, null); table.addTD(builddate, 1, null); table.addNewRow(); table.addTD("Systemzeit:", 1, null); table.addTD(Hilfsklasse.zeitstempelAlsString(), 1, null); table.addNewRow(); table.addTD("Zwischenablage:", 1, attributeLeftCol); String clip; if (model.getZwischenablage() != null) { clip = HTMLUtils.spacifyFilePath(model.getZwischenablage(), model); } else { clip = "[ leer ]"; } table.addTD(clip, 1, null); table.addNewRow(); table.addTD("Session:", 1, null); table.addTD(StringHelper.langenStringFuerAnzeigeAufbereiten(model.getSessionID()), 1, null); table.addNewRow(); table.addTD("Login:", 1, null); table.addTD(StringHelper.langenStringFuerAnzeigeAufbereiten(model.getLoginCookieID()), 1, null); table.addNewRow(); if (model.lookupConversation().getCookiesReadFromRequest() != null && model.isDevelopmentMode()) { for (Cookie cookieReadFromRequest : model.lookupConversation().getCookiesReadFromRequest()) { String cookieName = cookieReadFromRequest.getName(); String cookieValue = cookieReadFromRequest.getValue(); table.addTD("Cookie (Request):", 1, null); table.addTD(cookieName, 1, null); table.addNewRow(); table.addTD("", 1, null); table.addTD(StringHelper.langenStringFuerAnzeigeAufbereiten(cookieValue), 1, null); table.addNewRow(); } } table.addTD("Conversation ID:", 1, null); table.addTD(model.lookupConversation().getConversationID().toString(), 1, null); table.addNewRow(); table.addTD("Remote IP:", 1, null); table.addTD(parameters.get(ServletHelper.SERVLET_REMOTE_IP), 1, null); table.addNewRow(); table.addTD("LocalNetwork:", 1, null); table.addTD(ServletHelper.isLocalNetworkClient(parameters) + "", 1, null); table.addNewRow(); table.addTD("Touch / Phone / Tablet:", 1, null); table.addTD(Boolean.toString(model.isClientTouchDevice()) + " / " + Boolean.toString(model.isPhone()) + " / " + Boolean.toString(model.isTablet()), 1, null); table.addNewRow(); table.addTD("Ist FullScreen:", 1, null); table.addTD(Boolean.toString(model.isIstWebApp()), 1, null); table.addNewRow(); table.addTD("Ajax / current request:", 1, null); table.addTD(Boolean.toString(ServletHelper.lookupUseAjax()) + " / " + ServletHelper.lookupIsCurrentRequestTypeAjax(parameters), 1, null); table.addNewRow(); table.addTD("Gzip Response:", 1, null); table.addTD(Boolean.toString(ServletHelper.lookupUseGzip(parameters)), 1, null); table.addNewRow(); if (model.isPhone()) { sb.append(table.buildTable(model)); table = new HTMLTable(); } table.addTD("Java", 2, HTMLTable.TABLE_HEADER); table.addNewRow(); table.addTD("total / max memory:", 1, attributeLeftCol); table.addTD(DateiZugriff.speicherGroesseFormatieren(Runtime.getRuntime().totalMemory()) + " / " + DateiZugriff.speicherGroesseFormatieren(Runtime.getRuntime().maxMemory()), 1, null); table.addNewRow(); table.addTD("freeMemory:", 1, null); table.addTD(DateiZugriff.speicherGroesseFormatieren(Runtime.getRuntime().freeMemory()), 1, null); table.addNewRow(); table.addTD("catalina.home:", 1, null); table.addTD( HTMLUtils.spacifyFilePath( System.getProperties().getProperty(ServletHelper.SYSTEM_PROPERTY_CATALINA_HOME), model), 1, null); table.addNewRow(); table.addTD("catalina.base:", 1, null); table.addTD( HTMLUtils.spacifyFilePath( System.getProperties().getProperty(ServletHelper.SYSTEM_PROPERTY_CATALINA_BASE), model), 1, null); table.addNewRow(); table.addTD("WarFile:", 1, HTMLTable.NO_BORDER); table.addTD(HTMLUtils.spacifyFilePath(warfilename, model), 1, HTMLTable.NO_BORDER); table.addNewRow(); if (model.isPhone()) { sb.append(table.buildTable(model)); table = new HTMLTable(); } table.addTD("Hardware / Software", 2, HTMLTable.TABLE_HEADER); table.addNewRow(); table.addTD("CPU Cores:", 1, attributeLeftCol); table.addTD(Runtime.getRuntime().availableProcessors() + "", 1, null); table.addNewRow(); table.addTD("Architecture:", 1, null); table.addTD(System.getProperty("sun.arch.data.model", "") + " bit", 1, null); table.addNewRow(); table.addTD("Java Version:", 1, null); table.addTD(System.getProperty("java.version", ""), 1, null); table.addNewRow(); table.addTD("Java VM:", 1, null); table.addTD(System.getProperty("java.vm.name", ""), 1, null); table.addNewRow(); table.addTD("Server:", 1, null); table.addTD(KVMemoryMap.getInstance().readValueFromKey("application.server"), 1, null); table.addNewRow(); if (model.isPhone()) { sb.append(table.buildTable(model)); table = new HTMLTable(); } table.addTD("Cron Jobs", 2, HTMLTable.TABLE_HEADER); table.addNewRow(); int a = 0; List<String> jobs = new LinkedList<String>(); jobs.add(""); for (String schedulerName : CronSchedulers.getInstance().getSchedulersIDs().keySet()) { jobs.add(schedulerName); String cssClass = a % 2 != 0 ? attributeLeftCol : HTMLUtils.buildAttribute("class", "alt"); Scheduler s = CronSchedulers.getInstance().getSchedulers().get(schedulerName); table.addTD(schedulerName, 1, cssClass); table.addTD(((s != null && s.isStarted()) ? "@ " : "not running") + CronSchedulers.getInstance().lookupCronStringOfScheduler(schedulerName), 1, cssClass); table.addNewRow(); table.addTD("", 1, cssClass); table.addTD(CronSchedulers.getInstance().getSchedulersInstances().get(schedulerName).status(), 1, cssClass); table.addNewRow(); a++; } if (model.isPhone()) { sb.append(table.buildTable(model)); table = new HTMLTable(); } table.addTD("Manueller Job-Start", 2, HTMLTable.TABLE_HEADER); table.addNewRow(); table.addTDSource(HTMLUtils.buildDropDownListe("execute_job", jobs, null), 2, null); table.addNewRow(); String buttonJobStart = new Button("Job starten", Condition.SYS_EXECUTE_JOB).printForUseInTable(); table.addTDSource(buttonJobStart, 2, HTMLTable.NO_BORDER); table.addNewRow(); sb.append(table.buildTable(model)); return; }
From source file:org.apache.drill.exec.client.DrillClient.java
public synchronized void connect(String connect, Properties props) throws RpcException { if (connected) { return;// w w w . ja v a 2s.c o m } final List<DrillbitEndpoint> endpoints = new ArrayList<>(); if (isDirectConnection) { // Populate the endpoints list with all the drillbit information provided in the connection string endpoints.addAll(parseAndVerifyEndpoints(props.getProperty("drillbit"), config.getString(ExecConstants.INITIAL_USER_PORT))); } else { if (ownsZkConnection) { try { this.clusterCoordinator = new ZKClusterCoordinator(this.config, connect); this.clusterCoordinator.start(10000); } catch (Exception e) { throw new RpcException("Failure setting up ZK for client.", e); } } endpoints.addAll(clusterCoordinator.getAvailableEndpoints()); // Make sure we have at least one endpoint in the list checkState(!endpoints.isEmpty(), "No active Drillbit endpoint found from ZooKeeper"); } // shuffle the collection then get the first endpoint Collections.shuffle(endpoints); final DrillbitEndpoint endpoint = endpoints.get(0); if (props != null) { final UserProperties.Builder upBuilder = UserProperties.newBuilder(); for (final String key : props.stringPropertyNames()) { upBuilder.addProperties(Property.newBuilder().setKey(key).setValue(props.getProperty(key))); } this.props = upBuilder.build(); } eventLoopGroup = createEventLoop(config.getInt(ExecConstants.CLIENT_RPC_THREADS), "Client-"); executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory("drill-client-executor-")) { @Override protected void afterExecute(final Runnable r, final Throwable t) { if (t != null) { logger.error("{}.run() leaked an exception.", r.getClass().getName(), t); } super.afterExecute(r, t); } }; client = new UserClient(clientName, config, supportComplexTypes, allocator, eventLoopGroup, executor); logger.debug("Connecting to server {}:{}", endpoint.getAddress(), endpoint.getUserPort()); connect(endpoint); connected = true; }
From source file:jp.terasoluna.fw.web.struts.form.DynaValidatorActionFormExTest.java
/** * ????s?B/*from ww w . j a v a 2 s.c o m*/ * * @throws Exception ?\bh?O * @see junit.framework.TestCase#setUp() */ @SuppressWarnings("unchecked") @Override protected void setUp() throws Exception { super.setUp(); // create formEx // ?set?\bh?o?Av?peB?L?qt@Cw this.formEx = (DynaValidatorActionFormEx) creator.create(CONFIG_FILE_PATH); // i[l?? int hogeInt = 123; String hogeString = "data1"; int[] hogeIntArray = { -100, 0, 10, 111 }; String[] hogeStringArray = new String[4]; Object[] hogeObjectArray = new Object[4]; List<Object> hogeList = new ArrayList<Object>(); Map<String, Object> hogeMap = new HashMap<String, Object>(); Runnable hogeRunnable = new Runnable() { public void run() { } }; boolean hogeBoolean = true; byte hogeByte = 1; char hogeChar = 'A'; double hogeDouble = 999.9; float hogeFloat = 999; short hogeShort = 9; long hogeLong = 9; for (int i = 0; i < 4; i++) { hogeStringArray[i] = "data" + (i + 1); hogeObjectArray[i] = new Integer(i + 1); hogeList.add(i, "data" + (i + 1)); hogeMap.put("field" + (i + 1), "data" + (i + 1)); } String[] fields = { "hogeInt", "hogeString", "hogeIntArray", "hogeStringArray", "hogeObjectArray", "hogeList", "hogeMap", "hogeRunnable", "hogeBoolean", "hogeByte", "hogeChar", "hogeDouble", "hogeFloat", "hogeShort", "hogeLong" }; Class[] fieldClasses = { int.class, hogeString.getClass(), hogeIntArray.getClass(), hogeStringArray.getClass(), hogeObjectArray.getClass(), hogeList.getClass(), hogeMap.getClass(), hogeRunnable.getClass(), boolean.class, byte.class, char.class, double.class, float.class, short.class, long.class }; DynaProperty[] props = new DynaProperty[fields.length]; HashMap<String, DynaProperty> propsMap = new HashMap<String, DynaProperty>(); for (int i = 0; i < fields.length; i++) { props[i] = new DynaProperty(fields[i], fieldClasses[i]); propsMap.put(props[i].getName(), props[i]); } DynaActionFormClass dynaActionFormClass = (DynaActionFormClass) UTUtil.getPrivateField(this.formEx, "dynaClass"); UTUtil.setPrivateField(dynaActionFormClass, "properties", props); UTUtil.setPrivateField(dynaActionFormClass, "propertiesMap", propsMap); Map<String, Object> map = (Map) UTUtil.getPrivateField(this.formEx, "dynaValues"); map.put("hogeInt", hogeInt); map.put("hogeString", hogeString); map.put("hogeIntArray", hogeIntArray); map.put("hogeStringArray", hogeStringArray); map.put("hogeObjectArray", hogeObjectArray); map.put("hogeList", hogeList); map.put("hogeMap", hogeMap); map.put("hogeRunnable", hogeRunnable); map.put("hogeBoolean", hogeBoolean); map.put("hogeByte", hogeByte); map.put("hogeChar", hogeChar); map.put("hogeDouble", hogeDouble); map.put("hogeFloat", hogeFloat); map.put("hogeShort", hogeShort); map.put("hogeLong", hogeLong); }