use of java.util.TimerTask in project EnrichmentMapApp by BaderLab.
the class CreateDiseaseSignatureTaskParallel method run.
@Override
public void run(TaskMonitor tm) throws InterruptedException {
int cpus = Runtime.getRuntime().availableProcessors();
ExecutorService executor = Executors.newFixedThreadPool(cpus);
// Compare enrichment gene sets to signature gene sets
Set<String> enrichmentGeneSetNames = getEnrichmentGeneSetNames();
Map<String, GeneSet> signatureGeneSets = getSignatureGeneSets();
handleDuplicateNames(enrichmentGeneSetNames, signatureGeneSets);
Map<SimilarityKey, GenesetSimilarity> geneSetSimilarities = startBuildDiseaseSignatureParallel(tm, executor, enrichmentGeneSetNames, signatureGeneSets);
// Support cancellation
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
if (cancelled) {
executor.shutdownNow();
}
}
}, 0, 1000);
executor.shutdown();
executor.awaitTermination(3, TimeUnit.HOURS);
timer.cancel();
// create the network here
if (!cancelled) {
Task networkTask = networkTaskFactory.create(map, params, signatureGeneSets, geneSetSimilarities);
insertTasksAfterCurrentTask(networkTask);
}
}
use of java.util.TimerTask in project zxing by zxing.
the class DoSFilter method init.
@Override
public void init(FilterConfig filterConfig) {
timer = new Timer("DoSFilter reset timer");
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
numRecentAccesses.clear();
}
}, 0L, TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES));
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
bannedIPAddresses.clear();
}
}, 0L, TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES));
}
use of java.util.TimerTask in project HomeMirror by HannahMitt.
the class CountdownModule method getTimeRemaining.
public static void getTimeRemaining(final Date countdownEnd, final CountdownListener listener) {
if (timer != null) {
timer.cancel();
}
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
long timeLeft = countdownEnd.getTime() - System.currentTimeMillis();
listener.onCountdownUpdate(formatTime(timeLeft));
}
}, 0, 1000);
}
use of java.util.TimerTask in project android_frameworks_base by DirtyUnicorns.
the class SystemServer method run.
private void run() {
try {
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "InitBeforeStartServices");
// hope that time from cell towers or NTP fixes it shortly.
if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Slog.w(TAG, "System clock is before 1970; setting to 1970.");
SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
}
// core/jni/AndroidRuntime.cpp
if (!SystemProperties.get("persist.sys.language").isEmpty()) {
final String languageTag = Locale.getDefault().toLanguageTag();
SystemProperties.set("persist.sys.locale", languageTag);
SystemProperties.set("persist.sys.language", "");
SystemProperties.set("persist.sys.country", "");
SystemProperties.set("persist.sys.localevar", "");
}
// Here we go!
Slog.i(TAG, "Entered the Android system server!");
EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, SystemClock.uptimeMillis());
// In case the runtime switched since last boot (such as when
// the old runtime was removed in an OTA), set the system
// property so that it is in sync. We can't do this in
// libnativehelper's JniInvocation::Init code where we already
// had to fallback to a different runtime because it is
// running as root and we need to be the system user to set
// the property. http://b/11463182
SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary());
// Enable the sampling profiler.
if (SamplingProfilerIntegration.isEnabled()) {
SamplingProfilerIntegration.start();
mProfilerSnapshotTimer = new Timer();
mProfilerSnapshotTimer.schedule(new TimerTask() {
@Override
public void run() {
SamplingProfilerIntegration.writeSnapshot("system_server", null);
}
}, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
}
// Mmmmmm... more memory!
VMRuntime.getRuntime().clearGrowthLimit();
// The system server has to run all of the time, so it needs to be
// as efficient as possible with its memory usage.
VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
// Some devices rely on runtime fingerprint generation, so make sure
// we've defined it before booting further.
Build.ensureFingerprintProperty();
// Within the system server, it is an error to access Environment paths without
// explicitly specifying a user.
Environment.setUserRequired(true);
// Within the system server, any incoming Bundles should be defused
// to avoid throwing BadParcelableException.
BaseBundle.setShouldDefuse(true);
// Ensure binder calls into the system always run at foreground priority.
BinderInternal.disableBackgroundScheduling(true);
// Increase the number of binder threads in system_server
BinderInternal.setMaxThreads(sMaxBinderThreads);
// Prepare the main looper thread (this thread).
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_FOREGROUND);
android.os.Process.setCanSelfBackground(false);
Looper.prepareMainLooper();
// Initialize native services.
System.loadLibrary("android_servers");
// Check whether we failed to shut down last time we tried.
// This call may not return.
performPendingShutdown();
// Initialize the system context.
createSystemContext();
// Create the system service manager.
mSystemServiceManager = new SystemServiceManager(mSystemContext);
mSystemServiceManager.setRuntimeRestarted(mRuntimeRestart);
LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
}
// Start services.
try {
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartServices");
startBootstrapServices();
startCoreServices();
startOtherServices();
} catch (Throwable ex) {
Slog.e("System", "******************************************");
Slog.e("System", "************ Failure starting system services", ex);
throw ex;
} finally {
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
}
// For debug builds, log event loop stalls to dropbox for analysis.
if (StrictMode.conditionallyEnableDebugLogging()) {
Slog.i(TAG, "Enabled StrictMode for system server main thread.");
}
// Loop forever.
Looper.loop();
throw new RuntimeException("Main thread loop unexpectedly exited");
}
use of java.util.TimerTask in project opennms by OpenNMS.
the class RemotePollerAvailabilityService method getAvailability.
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("availability")
public OnmsLocationAvailDefinitionList getAvailability(@Context final UriInfo uriInfo) throws InterruptedException {
if (m_timer == null) {
final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
m_defList = getAvailabilityList(createTimeChunker(queryParameters), getSortedApplications(), null, getSelectedNodes(queryParameters));
TimerTask task = new TimerTask() {
@Override
public void run() {
m_defList = m_transactionTemplate.execute(new TransactionCallback<OnmsLocationAvailDefinitionList>() {
@Override
public OnmsLocationAvailDefinitionList doInTransaction(TransactionStatus status) {
return getAvailabilityList(getTimeChunkerFromMidnight(), getSortedApplications(), null, null);
}
});
}
};
m_timer = new Timer("AvailCalculator-Timer");
m_timer.scheduleAtFixedRate(task, TimeChunker.MINUTE, TimeChunker.MINUTE);
}
return m_defList;
}
Aggregations