List of usage examples for java.util Timer Timer
public Timer()
From source file:ca.canucksoftware.ipkpackager.IpkPackagerView.java
public IpkPackagerView(SingleFrameApplication app) { super(app);// w w w . j a v a 2s . co m initComponents(); folder = null; postinst = null; prerm = null; pmPostInstall = null; pmPreRemove = null; isExpanded = false; depends = new ArrayList<String>(); ssURLs = new ArrayList<String>(); jTextField5.setDocument(new DocumentFilter(DocumentFilter.ALPHA_NUMERIC)); jTextField6.setDocument(new DocumentFilter(DocumentFilter.FLOAT)); jTextField18.setDocument(new DocumentFilter(DocumentFilter.FLOAT)); jTextField19.setDocument(new DocumentFilter(DocumentFilter.FLOAT)); t = new Timer(); t.schedule(new ResizeScreen(), 50); t.schedule(new DelayedLoad(), 50); }
From source file:ca.blackperl.WordFilterStreamBuilder.java
public void main() { // create the twitter search listener PhraseListener listener = new PhraseListener(args); // Connect to twitter. final TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); // The listener to the twitter connection twitterStream.addListener(listener); // Build a search configuration ArrayList<Long> follow = new ArrayList<Long>(); ArrayList<String> track = new ArrayList<String>(); for (String arg : args) { if (isNumericalArgument(arg)) { for (String id : arg.split(",")) { follow.add(Long.parseLong(id)); }//from www .j ava 2 s. c o m } else { track.addAll(Arrays.asList(arg.split(","))); } } long[] followArray = new long[follow.size()]; for (int i = 0; i < follow.size(); i++) { followArray[i] = follow.get(i); } String[] trackArray = track.toArray(new String[track.size()]); // filter() method internally creates a thread which manipulates // TwitterStream and calls the listener methods continuously. // pass the search configuration to the twitter library to start the search twitterStream.filter(new FilterQuery(0, followArray, trackArray)); // Create a timer final Timer timer = new Timer(); // Create a task to run every minute, starting in one minute. TimerTask summaryTask = new SummaryTask(listener, timer, twitterStream); timer.schedule(summaryTask, TimeToRunInSeconds * 1000, TimeToRunInSeconds * 1000); }
From source file:RolloverFileOutputStream.java
public RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone) throws IOException { super(null);/*from w w w.ja v a 2s .co m*/ _fileBackupFormat.setTimeZone(zone); _fileDateFormat.setTimeZone(zone); if (filename != null) { filename = filename.trim(); if (filename.length() == 0) filename = null; } if (filename == null) throw new IllegalArgumentException("Invalid filename"); _filename = filename; _append = append; _retainDays = retainDays; setFile(); synchronized (RolloverFileOutputStream.class) { if (__rollover == null) __rollover = new Timer(); _rollTask = new RollTask(); Calendar now = Calendar.getInstance(); now.setTimeZone(zone); GregorianCalendar midnight = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), 23, 0); midnight.setTimeZone(zone); midnight.add(Calendar.HOUR, 1); __rollover.scheduleAtFixedRate(_rollTask, midnight.getTime(), 1000L * 60 * 60 * 24); } }
From source file:monitoring.tools.AppTweak.java
private void resetStream() { logger.debug("Initialising streaming"); //this.kafka.initProducer(this.params.getKafkaEndpoint()); this.kafka.initProxy(this.params.getKafkaEndpoint()); firstConnection = true;//from www . j a v a2 s .c o m timer = new Timer(); timer.schedule(new TimerTask() { public void run() { if (firstConnection) { logger.debug("Connection established"); initTime = new Date(); firstConnection = false; } else { stamp = initTime; initTime = new Date(); try { apiCall(); } catch (IOException e) { logger.error("The API call was not correctly build"); } catch (JSONException | ParseException e) { logger.error("The response provided by the API tool was not a valid JSON object"); } } } }, 0, Integer.parseInt(params.getTimeSlot()) * 1000); }
From source file:monitoring.tools.GooglePlayAPI.java
private void resetStream() throws Exception { //this.kafka.initProducer(this.params.getKafkaEndpoint()); this.kafka.initProxy(this.params.getKafkaEndpoint()); firstConnection = true;//from ww w . ja v a2s . c o m generateNewAccessToken(); timer = new Timer(); timer.schedule(new TimerTask() { public void run() { if (firstConnection) { logger.debug("Connection established"); initTime = new Date(); firstConnection = false; } else { stamp = initTime; initTime = new Date(); try { apiCall(); } catch (IOException e) { logger.debug("Invalid access token. Generating a new one"); try { generateNewAccessToken(); apiCall(); } catch (IOException e1) { logger.error("There was an unexpected error with the API call"); } } } } }, 0, Integer.parseInt(params.getTimeSlot()) * 1000); }
From source file:com.dangdang.config.service.zookeeper.ZookeeperConfigGroup.java
/** * ?//from w w w . java 2 s .c om */ private void initConfigs() { client = CuratorFrameworkFactory.newClient(configProfile.getConnectStr(), configProfile.getRetryPolicy()); client.start(); client.getCuratorListenable().addListener(listener); LOGGER.debug("Loading properties for node: {}, with loading mode: {} and keys specified: {}", node, configProfile.getKeyLoadingMode(), configProfile.getKeysSpecified()); loadNode(); // Update local cache if (configLocalCache != null) { configLocalCache.saveLocalCache(this, node); } // Consistency check if (configProfile.isConsistencyCheck()) { timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { LOGGER.trace("Do consistency check for node: {}", node); loadNode(); } }, 60000L, configProfile.getConsistencyCheckRate()); } }
From source file:burstcoin.jminer.core.network.Network.java
@PostConstruct protected void postConstruct() { timer = new Timer(); poolMining = CoreProperties.isPoolMining(); if (poolMining) { String poolServer = CoreProperties.getPoolServer(); String numericAccountId = CoreProperties.getNumericAccountId(); if (!StringUtils.isEmpty(poolServer) && !StringUtils.isEmpty(numericAccountId)) { this.poolServer = CoreProperties.getPoolServer(); this.numericAccountId = CoreProperties.getNumericAccountId(); this.walletServer = CoreProperties.getWalletServer(); this.winnerRetriesOnAsync = CoreProperties.getWinnerRetriesOnAsync(); this.winnerRetryIntervalInMs = CoreProperties.getWinnerRetryIntervalInMs(); this.devPool = CoreProperties.isDevPool(); } else {/* ww w . jav a2s . c o m*/ LOG.error("init pool network failed!"); LOG.error("jminer.properties: 'poolServer' or 'numericAccountId' is missing?!"); } } else { String soloServer = CoreProperties.getSoloServer(); String passPhrase = CoreProperties.getPassPhrase(); if (!StringUtils.isEmpty(soloServer) && !StringUtils.isEmpty(passPhrase)) { this.soloServer = soloServer; this.passPhrase = passPhrase; } else { LOG.error("init solo network failed!"); LOG.error("jminer.properties: 'soloServer' or 'passPhrase' is missing?!"); } } this.defaultTargetDeadline = CoreProperties.getTargetDeadline(); this.connectionTimeout = CoreProperties.getConnectionTimeout(); }
From source file:cycronix.CTandroid.CTAserver.java
/** Called when the activity is first created. */ @Override/*from ww w . j ava 2s. com*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSettings(); // Restore preferences copyAssets(); // copy assets to external storage setContentView(R.layout.main); statusET = (EditText) findViewById(R.id.myText); if (statusET != null) statusET.setText("Not Started."); statusET.setEnabled(false); myipET = (EditText) findViewById(R.id.myIP); if (myipET != null) myipET.setText(getIPAddress(true)); myipET.setEnabled(false); counterET = (EditText) findViewById(R.id.Counter); counterET.setEnabled(false); memoryET = (EditText) findViewById(R.id.Memory); memoryET.setEnabled(false); // status timer myTimer = new Timer(); myTimer.schedule(new TimerTask() { @Override public void run() { TimerMethod(); } }, 0, 1000); // check interval // get GUI objects serverPortET = (EditText) findViewById(R.id.serverPort); serverPortET.setText(serverPort); dataFolderET = (EditText) findViewById(R.id.dataFolder); dataFolderET.setText(dataFolder); runBtn = (RadioButton) findViewById(R.id.RunButton); stopBtn = (RadioButton) findViewById(R.id.StopButton); quitBtn = (RadioButton) findViewById(R.id.QuitButton); runBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!Running) { try { pLog("Starting up..."); putSettings(); Running = true; int port = Integer.valueOf(serverPortET.getText().toString()); String resourceFolderPath = Environment.getExternalStorageDirectory() + "/" + resourceFolder; String dataFolderPath = dataFolderET.getText().toString(); // full path if (!dataFolderPath.startsWith("/")) // relative to external storage dir dataFolderPath = Environment.getExternalStorageDirectory() + "/" + dataFolderPath; // CTserver.debug=true; cts = new CTserver(port, resourceFolderPath, dataFolderPath); // start local webserver cts.start(); serverPortET.setEnabled(false); dataFolderET.setEnabled(false); pLog("Running!"); } catch (Exception e) { pLog("CTserver Launch Error: " + e); finish(); } } } }); stopBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Running) { pLog("Shutting down..."); // stopSource(); Running = false; putSettings(); if (cts != null) cts.stop(); // stop local webserver pLog("Stopped."); serverPortET.setEnabled(true); dataFolderET.setEnabled(true); System.gc(); // force a garbage collection } } }); quitBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pLog("Quitting App..."); Running = false; stopBtn.setChecked(true); putSettings(); finish(); } }); }
From source file:org.hxzon.demo.jfreechart.PolarChartDemo.java
public PolarChartDemo(String title) { super(title); PolarChartPanel chartPanel = new PolarChartPanel(polarChart1); //have a bug after show tooltips // chartPanel.setHorizontalAxisTrace(true); // chartPanel.setVerticalAxisTrace(true); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseWheelEnabled(true); chartPanel.addMouseListener(new MyChartClickHandler(chartPanel)); chartPanel.setPreferredSize(new Dimension(500, 270)); getContentPane().add(chartPanel);// w ww. j ava 2 s .c om getContentPane().add(new ChartComboBox(chartPanel), BorderLayout.SOUTH); Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { addValue(); } }, 0, 200); }
From source file:com.hs.mail.container.simple.SimpleSpringContainer.java
private static void startPerformanceMonitor(String interval) { int period = Integer.parseInt(interval); Timer timer = new Timer(); TimerTask memoryTask = new TimerTask() { ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); @Override/*from ww w .j a va2 s . c o m*/ public void run() { int threadCount = threadBean.getThreadCount(); int peakThreadCount = threadBean.getPeakThreadCount(); MemoryUsage heap = memoryBean.getHeapMemoryUsage(); MemoryUsage nonHeap = memoryBean.getNonHeapMemoryUsage(); System.out.println(sdf.format(System.currentTimeMillis()) + "\t threads=" + threadCount + ";peakThreads=" + peakThreadCount + ";heap=" + heap + ";non-heap=" + nonHeap); } }; timer.schedule(memoryTask, 0, period * 1000); }