Package java.util

Examples of java.util.Timer


   }

   private void startInTx()
   {
      // JBAS-4330, provide a meaningful name to the timer thread, needs jdk5+
      utilTimer = new Timer("EJB-Timer-" + timerId + timedObjectId);
     
      if (timerService.getTransaction() != null)
      {
         // don't schedule the timeout yet
         setTimerState(STARTED_IN_TX);
View Full Code Here


          sessionTemporaryFolder.deleteOnExit();
        }
       
        // Launch a timer that updates modification date of the temporary folder each minute
        final long updateDelay = 60000;
        new Timer(true).schedule(new TimerTask() {
            @Override
            public void run() {
              // Ensure modification date is always growing in case system time was adjusted
              sessionTemporaryFolder.setLastModified(Math.max(System.currentTimeMillis(),
                  sessionTemporaryFolder.lastModified() + updateDelay));
            }
          }, updateDelay, updateDelay);
       
        if (siblingTemporaryFolders != null
            && siblingTemporaryFolders.length > 0) {
          // Launch a timer that will delete in 10 min temporary folders older than a week
          final long deleteDelay = 10 * 60000;
          final long age = 7 * 24 * 3600000;
          new Timer(true).schedule(new TimerTask() {
              @Override
              public void run() {
                long now = System.currentTimeMillis();
                for (File siblingTemporaryFolder : siblingTemporaryFolders) {
                  if (siblingTemporaryFolder.exists()
View Full Code Here

      this.timer.cancel();
      this.timer = null;
    }
    int autoSaveDelayForRecovery = this.application.getUserPreferences().getAutoSaveDelayForRecovery();
    if (autoSaveDelayForRecovery > 0) {
      this.timer = new Timer("autoSaveTimer", true);
      TimerTask task = new TimerTask() {
        @Override
        public void run() {
          if (System.currentTimeMillis() - lastAutoSaveTime > MINIMUM_DELAY_BETWEEN_AUTO_SAVE_OPERATIONS) {
            cloneAndSaveHomes();
View Full Code Here

        private final AtomicInteger receivedRequests = new AtomicInteger(0);
        private Timer timer;

        public void onInit() {
            timer = new Timer();
        }
View Full Code Here

 
    public static void main(String[] args) throws IOException {
       
        class ServerHandler implements IHttpRequestHandler {

            private final Timer timer = new Timer(false);
           
            public void onRequest(IHttpExchange exchange) throws IOException {
                String requestURI = exchange.getRequest().getRequestURI();
               
                if (requestURI.equals("/Events")) {
                    sendEventStream(exchange);
                   
                } else {
                    sendStaticContent(exchange, requestURI);
                }
            }
           
           
            private void sendStaticContent(IHttpExchange exchange, String uri) throws IOException {
                String page = "<html>\r\n " +
                              "  <head>\r\n" +
                              "     <script type='text/javascript'>\r\n" +
                              "        var source = new EventSource('Events');\r\n" +
                              "        source.onmessage = function (event) {\r\n" +
                              "          var ev = document.getElementById('events');\r\n" +
                              "          ev.innerHTML += \"data: \" + event.data;\r\n"+
                              "        };\r\n" +
                              "     </script>\r\n" +
                              "  </head>\r\n" +
                              "  <body>\r\n" +
                              "    Events:\r\n" +
                              "    <div id=\"events\"></div>\r\n" +
                              "  </body>\r\n" +
                              "</html>\r\n ";
               
                exchange.send(new HttpResponse(200, "text/html", page));
            }
           
           
            private void sendEventStream(final IHttpExchange exchange) throws IOException {

                // sending the response header
                final BodyDataSink sink = exchange.send(new HttpResponseHeader(200, "text/event-stream"));

               
                TimerTask tt = new TimerTask() {

                    private int id = Integer.parseInt(exchange.getRequest().getHeader("Last-Event-Id", "0"));
                   
                    public void run() {
                        try {
                            Event event = new Event(new Date().toString(), ++id);
                            sink.write(event.toString());
                        } catch (IOException ioe) {
                            cancel();
                            sink.destroy();
                        }
                    };
                };
               
                Event event = new Event();
                event.setRetryMillis(5 * 1000);
                sink.write(event.toString());
               
                timer.schedule(tt, 3000, 3000);
            }
        }

       
       
View Full Code Here

 
    public static void main(String[] args) throws IOException {
       
        class ServerHandler implements IHttpRequestHandler {

            private final Timer timer = new Timer(false);
           
            public void onRequest(IHttpExchange exchange) throws IOException {
                String requestURI = exchange.getRequest().getRequestURI();
               
                if (requestURI.equals("/ServerSentEventExample")) {
                    sendServerSendPage(exchange, requestURI);
                   
                } else if (requestURI.equals("/Events")) {
                    sendEventStream(exchange);
                   
                } else {
                    exchange.sendError(404);
                }
            }
           
           
            private void sendServerSendPage(IHttpExchange exchange, String uri) throws IOException {
                String page = "<html>\r\n " +
                              "  <head>\r\n" +
                              "     <script type='text/javascript'>\r\n" +
                              "        var source = new EventSource('Events');\r\n" +
                              "        source.onmessage = function (event) {\r\n" +
                              "          ev = document.getElementById('events');\r\n" +
                              "          ev.innerHTML += \"<br>[in] \" + event.data;\r\n"+
                              "        };\r\n" +
                              "     </script>\r\n" +
                              "  </head>\r\n" +
                              "  <body>\r\n" +
                              "    <div id=\"events\"></div>\r\n" +
                              "  </body>\r\n" +
                              "</html>\r\n ";
               
                exchange.send(new HttpResponse(200, "text/html", page));
            }
           

            private void sendEventStream(final IHttpExchange exchange) throws IOException {

                // get the last id string
                final String idString = exchange.getRequest().getHeader("Last-Event-Id", "0");

                // sending the response header
                final BodyDataSink sink = exchange.send(new HttpResponseHeader(200, "text/event-stream"));

                TimerTask tt = new TimerTask() {

                    private int id = Integer.parseInt(idString);
                   
                    public void run() {
                        try {
                            Event event = new Event(new Date().toString(), ++id);
                            sink.write(event.toString());
                        } catch (IOException ioe) {
                            cancel();
                            sink.destroy();
                        }
                    };
                };
               
                Event event = new Event();
                event.setRetryMillis(5 * 1000);
                event.setComment("time stream");
                sink.write(event.toString());
               
                timer.schedule(tt, 3000, 3000);
            }
        }

       
        HttpServer server = new HttpServer(8875, new ServerHandler());
View Full Code Here

      return;
    }

    log.debug("Starting secondary zone update timer...");
    this.timerTask = new RunnableTimerTask(this);
    this.secondaryZoneUpdateTimer = new Timer();
    this.secondaryZoneUpdateTimer.schedule(timerTask, MillisecondTimeUnits.SECOND * 60, MillisecondTimeUnits.SECOND * 60);

    log.info(VERSION + " started with " + this.primaryZoneMap.size() + " primary zones and " + this.secondaryZoneMap.size() + " secondary zones");
  }
View Full Code Here

    this.name = name;

    if(autoReloadZones && pollingInterval != null){

      watcher = new Timer(true);
      watcher.schedule(new RunnableTimerTask(this), 5000, pollingInterval);
    }
  }
View Full Code Here

    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        final long started = lastInsert = System.currentTimeMillis();
        if (!getSelectionWindow().isVisible()) {
          if (isAnyValueStartingWith(getLastWord())) {
            new Timer(true).schedule(new TimerTask() {
              public void run() {
                if (lastInsert == started
                    && !getSelectionWindow().isVisible()) {
                  model.fireChange();
                  showWindow();
View Full Code Here

        public void run() {
          printRate();
        }
      };
     
      new Timer(false).schedule(printTask, 3 * 1000, 3 * 1000);
     
     
      httpClient.setMaxActive(maxActive);
     
     
View Full Code Here

TOP

Related Classes of java.util.Timer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.