Example usage for java.util Timer schedule

List of usage examples for java.util Timer schedule

Introduction

In this page you can find the example usage for java.util Timer schedule.

Prototype

public void schedule(TimerTask task, Date time) 

Source Link

Document

Schedules the specified task for execution at the specified time.

Usage

From source file:com.theaetetuslabs.android_apkmaker.InstallActivity.java

@Override
protected void onResume() {
    super.onResume();
    Logger.logd("InstallActivity#onResume. signed path: " + files.signed.getAbsolutePath(), verbose,
            System.out);//ww w.j a va2 s  . com
    if (needStartInstall) {
        SideLoadChecker slc = new SideLoadChecker(this);

        if (!files.signed.exists()) {
            finish();
            return;
        }
        if (!slc.canSideLoad()) {
            slc.requestSideLoad();
            return;
        }
        needStartInstall = false;
        if (Build.VERSION.SDK_INT >= 24) {
            //can install from uri: 24
            //cannot install from uri: 23, 22, 19 or 16
            tryInstallInternal();
        } else {
            Timer timer = new Timer();
            timer.schedule(new TopDogCheck(timer, this), 100);
            moveApk();
        }
    }
}

From source file:org.punksearch.crawler.NetworkCrawler.java

private void startTimers() {
    Timer processTimer = new Timer();
    processTimer.schedule(new MaxRunWatchDog(), maxHours * 3600 * 1000L);

    Timer statusDumpTimer = new Timer();
    long dumpPeriod = Long.getLong(DUMP_STATUS_PERIOD, 10L) * 1000;
    statusDumpTimer.scheduleAtFixedRate(new ThreadStatusDump(), dumpPeriod, dumpPeriod);

    timers.add(processTimer);//from   ww  w  .  j  av a2s  .  com
    timers.add(statusDumpTimer);
}

From source file:com.andrada.sitracker.ui.fragment.AuthorsFragment.java

/**
 * Crouton click handler/*from  w w w.ja  v  a 2s.c o m*/
 *
 * @param view being clicked
 */
@Override
public void onClick(@NotNull View view) {
    if (view.getId() == R.id.retryUpdateButton) {
        if (this.mNoNetworkCrouton != null) {
            Crouton.hide(this.mNoNetworkCrouton);
            this.mNoNetworkCrouton = null;
        }
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                FragmentActivity activity = getActivity();
                if (activity != null) {
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            menuRefreshSelected();
                        }
                    });
                }
            }
        }, 1500);
    }

}

From source file:com.sunildhaker.watch.heart.ConnectActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_connect);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    //getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    btn = (CircledImageView) findViewById(R.id.btnConnect);

    btn.setOnClickListener(new View.OnClickListener() {
        @Override//from   w  w  w  . j ava2 s . c  o m
        public void onClick(View view) {
            if (gotText)
                displaySpeechRecognizer();
            else {

                Timer t = new Timer();
                TimerTask tt = new TimerTask() {
                    @Override
                    public void run() {
                        showNotification();
                    }
                };
                t.schedule(tt, 5000);

                System.exit(0);
            }
        }
    });
}

From source file:svc.managers.SMSManager.java

private String generateViewCitationsAgainMessage(HttpSession session, HttpServletRequest request,
        String menuChoice) {/*ww  w. j  av a2  s  . c om*/
    String message = "";
    String citationNumber = (String) session.getAttribute("citationNumber");
    String courtDateTime = (String) session.getAttribute("courtDateTime");
    String phoneNumber = (String) session.getAttribute("phoneNumber");
    String dob = (String) session.getAttribute("dob");

    switch (menuChoice) {
    case "1":
        message = generateReadLicenseMessage(session);
        break;
    case "2":
        message = "Visit ";
        message += clientURL + "/citations";
        message += "/" + citationNumber;
        message += replyWithAdditionalViewingOptions();
        setNextStageInSession(session, SMS_STAGE.READ_MENU_CHOICE_VIEW_CITATIONS_AGAIN);
        break;
    case "3":
        if (smsAlertManager.add(citationNumber, LocalDateTime.parse(courtDateTime), phoneNumber,
                DatabaseUtilities.convertUSStringDateToLD(dob))) {
            //if a demo citation was created automatically send out an sms alert in 1 minute.
            if (citationNumber.startsWith("STLC")) {
                Timer timer = new Timer();
                timer.schedule(new TimerTask() {

                    @Override
                    public void run() {
                        smsNotifier.sendAlerts(citationNumber, phoneNumber);
                        smsAlertManager.remove(citationNumber, phoneNumber,
                                DatabaseUtilities.convertUSStringDateToLD(dob));
                    }

                }, 1 * 60 * 1000);
            }

            message = "You will receive 3 text message reminders about your court date.  The first one will be sent two weeks prior to your court date.  The second will be send one week prior and the final one will be sent the day before your court date.";
            message += "\n\n  For help, respond HELP, to stop, respond STOP";
            message += "\n\n Responding with STOP will prevent you from receiving any reminders now and in the future as well as using any part of this SMS service.  If you'd like to cancel your reminder, you can cancel using the same text message menu you used to sign up.";
            message += "\n\n" + replyWithAdditionalViewingOptionsNoText();
            setNextStageInSession(session, SMS_STAGE.READ_MENU_CHOICE_VIEW_CITATIONS_AGAIN);
        } else {
            message = "Sorry, something went wrong in processing your request for text message reminders.";
            setNextStageInSession(session, SMS_STAGE.WELCOME);
        }
        break;
    case "4":
        if (smsAlertManager.remove(citationNumber, phoneNumber,
                DatabaseUtilities.convertUSStringDateToLD(dob))) {
            message = "You have been removed from receiving text message reminders about this court date.  If there are other court dates you have signed up to receive text message reminders for and you would like to be removed from receiving updates about those dates, please look them up by your citation number and remove them too.";
            message += replyWithAdditionalViewingOptionsNoText();
            setNextStageInSession(session, SMS_STAGE.READ_MENU_CHOICE_VIEW_CITATIONS_AGAIN);
        } else {
            message = "Sorry, something went wrong in processing your request to be removed from text message reminders.";
            setNextStageInSession(session, SMS_STAGE.WELCOME);
        }
        break;
    default:
        message = "Option not recognized.";
        message += replyWithAdditionalViewingOptions();
        setNextStageInSession(session, SMS_STAGE.READ_MENU_CHOICE_VIEW_CITATIONS_AGAIN);
        break;
    }

    return message;
}

From source file:org.apache.cloud.rdf.web.sail.RdfController.java

@RequestMapping(value = "/queryrdf", method = { RequestMethod.GET, RequestMethod.POST })
public void queryRdf(@RequestParam("query") final String query,
        @RequestParam(value = RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, required = false) String auth,
        @RequestParam(value = RdfCloudTripleStoreConfiguration.CONF_CV, required = false) final String vis,
        @RequestParam(value = RdfCloudTripleStoreConfiguration.CONF_INFER, required = false) final String infer,
        @RequestParam(value = "nullout", required = false) final String nullout,
        @RequestParam(value = RdfCloudTripleStoreConfiguration.CONF_RESULT_FORMAT, required = false) final String emit,
        @RequestParam(value = "padding", required = false) final String padding,
        @RequestParam(value = "callback", required = false) final String callback,
        final HttpServletRequest request, final HttpServletResponse response) {
    // WARNING: if you add to the above request variables,
    // Be sure to validate and encode since they come from the outside and could contain odd damaging character sequences.
    SailRepositoryConnection conn = null;
    final Thread queryThread = Thread.currentThread();
    auth = StringUtils.arrayToCommaDelimitedString(provider.getUserAuths(request));
    final Timer timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override//from  w  ww  .  j  a  va  2s.  c o  m
        public void run() {
            log.debug("interrupting");
            queryThread.interrupt();

        }
    }, QUERY_TIME_OUT_SECONDS * 1000);

    try {
        final ServletOutputStream os = response.getOutputStream();
        conn = repository.getConnection();

        final Boolean isBlankQuery = StringUtils.isEmpty(query);
        final ParsedOperation operation = QueryParserUtil.parseOperation(QueryLanguage.SPARQL, query, null);

        final Boolean requestedCallback = !StringUtils.isEmpty(callback);
        final Boolean requestedFormat = !StringUtils.isEmpty(emit);

        if (!isBlankQuery) {
            if (operation instanceof ParsedGraphQuery) {
                // Perform Graph Query
                final RDFHandler handler = new RDFXMLWriter(os);
                response.setContentType("text/xml");
                performGraphQuery(query, conn, auth, infer, nullout, handler);
            } else if (operation instanceof ParsedTupleQuery) {
                // Perform Tuple Query
                TupleQueryResultHandler handler;

                if (requestedFormat && emit.equalsIgnoreCase("json")) {
                    handler = new SPARQLResultsJSONWriter(os);
                    response.setContentType("application/json");
                } else {
                    handler = new SPARQLResultsXMLWriter(os);
                    response.setContentType("text/xml");
                }

                performQuery(query, conn, auth, infer, nullout, handler);
            } else if (operation instanceof ParsedUpdate) {
                // Perform Update Query
                performUpdate(query, conn, os, infer, vis);
            } else {
                throw new MalformedQueryException("Cannot process query. Query type not supported.");
            }
        }

        if (requestedCallback) {
            os.print(")");
        }
    } catch (final Exception e) {
        log.error("Error running query", e);
        throw new RuntimeException(e);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (final RepositoryException e) {
                log.error("Error closing connection", e);
            }
        }
    }

    timer.cancel();
}

From source file:com.loftcat.ui.utils.slidingmenu.fragment.LeftFragment.java

private void setListener() {
    _account_add_button.setOnClickListener(new TextView.OnClickListener() {

        @Override//from www .  j  av a2s.  c  om
        public void onClick(View v) {
            isAdd = true;
            mWeibo = Weibo.getInstance(BaseActivity.CONSUMER_KEY, BaseActivity.CONSUMER_SECRET,
                    BaseActivity.REDIRECT_URL);
            mWeibo.authorize(context, new AuthDialogListener());
        }
    });
    _account_listview.setOnItemLongClickListener(new ListView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) {

            if (accounts.size() > 1) {
                AlertDialog.Builder alertDialog = new AlertDialog.Builder(context).setTitle("??")
                        .setMessage("?")
                        .setPositiveButton("?", new AlertDialog.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                // TODO Auto-generated
                                // method stub

                            }
                        }).setNegativeButton("", new AlertDialog.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                isDelete = true;
                                delete_id = accounts.get(arg2).getUid();
                                _dBManager.deleteAccount(accounts.get(arg2));
                                Timer timer = new Timer();
                                timer.schedule(new TimerTask() {

                                    @Override
                                    public void run() {
                                        _handler.sendEmptyMessage(0);
                                    }
                                }, 150);
                                Toast.makeText(context, "~", Toast.LENGTH_LONG).show();
                            }
                        });
                alertDialog.show();
            } else {

            }

            return false;
        }

    });
    _account_listview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            for (int i = 0; i < imagelists.size(); i++) {
                if (i == arg2) {
                    imagelists.get(arg2).setVisibility(View.VISIBLE);
                    utility.keepIndex(Long.valueOf(accounts.get(i).getId()), _handler);
                } else {
                    imagelists.get(i).setVisibility(View.GONE);
                }
            }
            ((HomepageAty) getActivity()).setSince_id(0l);
            ((HomepageAty) getActivity()).setPage(1);
            ((HomepageAty) getActivity()).setAccount(accounts.get(arg2));
            ((HomepageAty) getActivity()).showRight();
        }

    });
    self.setOnClickListener(new TextView.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent();
            intent.putExtra("userID", ((HomepageAty) getActivity()).get_account().getId());
            intent.putExtra("self", true);
            intent.setAction(AppConfig.INTENT_ACTION_SELFPAGE);
            startActivity(intent);
        }
    });
    weibo.setOnClickListener(new TextView.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            ((HomepageAty) getActivity()).showLeft();
        }
    });
    comments.setOnClickListener(new TextView.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction("com.loftcat.ui.CommentsListAty");
            intent.putExtra("mode", "all");
            startActivity(intent);
        }
    });
    atme.setOnClickListener(new TextView.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction("com.loftcat.ui.CommentsListAty");
            intent.putExtra("mode", "at");
            startActivity(intent);
        }
    });
}

From source file:coria2015.server.JsonRPCMethods.java

/**
     * Shutdown the server/* www .jav  a 2s  .  c  o  m*/
     */
    @RPCMethod(help = "Shutdown Experimaestro server")
    public boolean shutdown() {
        // Shutdown jetty (after 1s to allow this thread to finish)
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                boolean stopped = false;
                try {
                    server.stop();
                    stopped = true;
                } catch (Exception e) {
                    LOGGER.warning("Could not stop properly jetty");
                }
                if (!stopped)
                    synchronized (this) {
                        try {
                            wait(10000);
                        } catch (InterruptedException e) {
                            LOGGER.severe(e.toString());
                        }
                        System.exit(1);

                    }
            }
        }, 2000);

        // Everything's OK
        return true;
    }

From source file:deincraftlauncher.InstallController.java

@FXML
void Continue() {

    if (!loggedin) {
        popupMessage("Fehler: Bitte zuerst erst anmelden");

    } else {//from   w w w .  j  a v a2  s  .c  om

        System.out.println("Creating config file...");
        try {
            folder.mkdirs();
            config.createNewFile();
        } catch (IOException ex) {
            System.err.println("error creating config file: " + ex);
        }

        settings.setPassword(Password);
        settings.setUsername(Username);
        settings.setRAM(getDefaultRam());
        settings.save();

        /*folderLauncher = new File(targetPath + "Launcher");
        System.out.println("Launcher: " + folderLauncher);
        folderLauncher.mkdirs();
        folderGame = new File(targetPath + "Games");
        folderGame.mkdirs();*/
        createGameDir(targetPath);
        if (createDesktop.isSelected()) {
            createDesktopShortcut();
        }

        popupMessage("Installation abgeschlossen. Starte Minefactory Launcher...");
        mainPanel.setVisible(false);
        try {
            Thread.sleep(500);
        } catch (InterruptedException ex) {
            Logger.getLogger(InstallController.class.getName()).log(Level.SEVERE, null, ex);
        }
        File installlocation = new File(targetPath);
        installlocation.mkdirs();
        saveConfig();
        String jarFile = getDCFile();
        String command = "java -jar " + jarFile;
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.exit(0);
            }
        }, 4000);
        try {
            Process p = Runtime.getRuntime().exec("cmd /C " + command);
            BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            try {
                while ((line = stdout.readLine()) != null) {
                    System.out.println(line);
                }
            } catch (IOException e) {
                System.err.println(e);
            }
        } catch (IOException ex) {
            Logger.getLogger(InstallController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    System.out.println("Finishing setting dialog...");
}

From source file:gtu.jpa.hibernate.Rcdf002eDBUI.java

private JButton getJButton1x() {
    if (porcessDoAllBtn == null) {
        porcessDoAllBtn = new JButton();
        porcessDoAllBtn.setText("\u6392\u7a0b\u57f7\u884c");
        porcessDoAllBtn.setPreferredSize(new java.awt.Dimension(80, 54));
        porcessDoAllBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    String dateTime = processDoAllText.getText();
                    Validate.notBlank(dateTime, "");
                    Validate.isTrue(StringUtils.isNumeric(dateTime), "");
                    Validate.isTrue(StringUtils.isNumeric(dateTime), "");
                    Validate.isTrue(dateTime.length() == 14, "14");

                    SimpleDateFormat sdf = new SimpleDateFormat();
                    sdf.applyPattern("yyyyMMddHHmmss");
                    Date newDate = sdf.parse(dateTime);

                    Validate.isTrue(newDate.after(new Date()), "??");

                    setTitle(DateFormatUtils.format(newDate, "yyyy/MM/dd HH:mm:ss") + "?...");
                    Timer timer = new Timer();
                    timer.schedule(new TimerTask() {
                        @Override
                        public void run() {
                            oneClickDoAll();
                        }// w  ww.  j a  v a2s  .c om
                    }, newDate);
                } catch (Exception ex) {
                    JCommonUtil.handleException(ex);
                    setTitle("......" + ex.getMessage());
                }
            }
        });
    }
    return porcessDoAllBtn;
}