Example usage for java.util Timer Timer

List of usage examples for java.util Timer Timer

Introduction

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

Prototype

public Timer() 

Source Link

Document

Creates a new timer.

Usage

From source file:com.spend.spendService.DomainLearning.java

private void GetNewQuery() {
    try {/* ww w .  j av  a  2s.c o m*/
        TimerTask timertask = new TimerTask() {
            public void run() {
                try {
                    domainList = new ArrayList<String>();
                    String[] seList = getSearchEngineNamesArray();
                    /* get urls from seedurlraw table */
                    PreparedStatement psmt = con.prepareStatement("SELECT url FROM seedurlraw");
                    ResultSet rs = psmt.executeQuery();
                    String regex = "[/]";
                    String regex2 = "[.]";
                    String PLDomain;
                    while (rs.next()) {
                        PLDomain = rs.getString("url");
                        PLDomain = PLDomain.replaceAll("http://|https://", "");
                        Pattern p = Pattern.compile(regex);
                        Matcher m = p.matcher(PLDomain);
                        if (m.find()) {
                            PLDomain = PLDomain.substring(0, m.start());
                        }
                        Pattern p2 = Pattern.compile(regex2);
                        Matcher m2 = p2.matcher(PLDomain);
                        int count = 0;
                        while (m2.find()) {
                            count++;
                        }
                        m2 = p2.matcher(PLDomain);
                        if (count > 1 && m2.find()) {
                            PLDomain = PLDomain.substring(m2.end());
                        }

                        //System.out.println(PLDomain);                        

                        if (!domainList.contains(PLDomain)) {
                            domainList.add(PLDomain);
                            newQuery = "sparql endpoint site:" + PLDomain;
                            for (Object se : seList) {
                                PreparedStatement psmt1 = con.prepareStatement(
                                        "INSERT INTO searchqueue(searchText,disabled,searchEngineName) VALUES(?,0,?);");
                                psmt1.setString(1, newQuery);
                                psmt1.setString(2, se.toString());
                                psmt1.executeUpdate();
                                psmt1.close();
                            }
                        }
                    }
                } catch (Exception ex) {
                    System.out
                            .println("DomainLearning.java timertask run function SQL ERROR " + ex.getMessage());
                }
            }
        };
        Timer timer = new Timer();
        DateFormat dateformat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        Date date = dateformat.parse("20-07-2017 00:00:00"); // set date and time
        timer.schedule(timertask, date, 1000 * 60 * 60 * 24 * 7); // for a week 1000*60*60*24*7
    } catch (Exception ex) {
        System.out.println("DomainLearning.java GetNewQuery function ERROR " + ex.getMessage());
    }
}

From source file:eu.esdihumboldt.hale.io.wfs.ui.capabilities.WFSCapabilitiesFieldEditor.java

/**
 * Schedule the validation//w  w  w .  j  a va2s . co  m
 */
protected void scheduleValidation() {
    final Display display = Display.getCurrent();

    synchronized (this) {
        if (timer != null) {
            timer.cancel();
        }

        // invalidate
        invalidate();

        // schedule validation
        timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                display.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        BusyIndicator.showWhile(display, new Runnable() {

                            @Override
                            public void run() {
                                refreshValidState();
                            }
                        });
                    }
                });
            }
        }, MODIFY_VALIDATE_DELAY);
    }
}

From source file:com.lib.DstabiProvider.java

private void startCecurityTimer() {
    Log.d(TAG, "zapinam timer");
    securityTimer = new Timer();
    securityTimer.schedule(new TimerTask() {
        @Override//from  w  w w.  j a  v  a2 s  .c o  m
        public void run() {
            TimerMethod();
        }

    }, 7000, 7000);
}

From source file:org.apache.james.ESReporterTest.java

@Before
public void setup() throws Exception {
    server = cassandraJmap.jmapServer();
    server.start();//from  w ww .  ja  va  2  s .c  om
    DataProbeImpl serverProbe = server.getProbe(DataProbeImpl.class);
    serverProbe.addDomain(DOMAIN);
    serverProbe.addUser(USERNAME, PASSWORD);

    RestAssured.requestSpecification = new RequestSpecBuilder().setContentType(ContentType.JSON)
            .setAccept(ContentType.JSON)
            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
            .setPort(server.getProbe(JmapGuiceProbe.class).getJmapPort()).build();
    accessToken = HttpJmapAuthentication.authenticateJamesUser(baseUri(), USERNAME, PASSWORD);

    timer = new Timer();
}

From source file:DynamiskDemo2.java

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title.//from  w ww . j  av a2 s  .c  o m
 */
public DynamiskDemo2(final String title) {

    super(title);
    this.series = new XYSeries(title, false, false);
    final XYSeriesCollection dataset = new XYSeriesCollection(this.series);
    final JFreeChart chart = createChart(dataset);

    final ChartPanel chartPanel = new ChartPanel(chart);
    final JButton button = new JButton("Add New Data Item");
    button.setActionCommand("ADD_DATA");
    button.addActionListener(this);

    final JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel);
    content.add(button, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);
    String fil = "C:" + File.separator + "Users" + File.separator + "madso" + File.separator + "Documents"
            + File.separator + "!Privat" + File.separator + "DTU 2016-2020" + File.separator + "MATLAB";
    String filnavn = "EKGdata";
    try {
        Scanner sc = new Scanner(new FileReader(fil + File.separator + filnavn));

        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                if (sc.hasNext()) {
                    final double newItem = Double.parseDouble(sc.next());
                    series.add(x, newItem);
                    x += 10;
                }
            }

        }, 100, 2);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:edu.stanford.junction.props2.Prop.java

public Prop(String propName, String propReplicaName, IPropState state, long seqNum) {
    this.propName = propName;
    this.cleanState = state;
    this.state = state.copy();
    this.sequenceNum = seqNum;
    this.propReplicaName = propReplicaName;
    taskTimer = new Timer();
    taskTimer.schedule(new PeriodicTask(), 0, 1000);
}

From source file:com.github.woonsan.commons.scxml.examples.stopwatch.StopWatchFrame.java

private void initUI() {
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    setContentPane(mainPanel);//from  ww w . ja v  a 2 s. co  m

    JPanel contentPanel = new JPanel();
    contentPanel.setLayout(new FlowLayout());
    displayLabel = new JLabel("0:00:00,000");
    contentPanel.add(displayLabel, BorderLayout.CENTER);

    mainPanel.add(contentPanel, BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());

    startButton = createButton("START", "Start");
    buttonPanel.add(startButton);

    stopButton = createButton("STOP", "Stop");
    stopButton.setEnabled(false);
    buttonPanel.add(stopButton);

    resetButton = createButton("RESET", "Reset");
    resetButton.setEnabled(false);
    buttonPanel.add(resetButton);

    mainPanel.add(buttonPanel, BorderLayout.SOUTH);

    pack();

    setLocation(200, 200);
    setSize(260, 80);

    setResizable(true);
    setVisible(true);

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Timer displayTimer = new Timer();
    displayTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            displayLabel.setText(stopWatch.getDisplay());
        }
    }, 100, 100);
}

From source file:com.mydlp.ui.service.LicenseServiceImpl.java

protected void scheduleLicenseCheck(final int delay) {
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        public void run() {
            scheduleLicenseCheckFun();//from ww w .  j  av  a 2s  . co  m
            if (!licenseAcquired && retryCounter > 0) {
                retryCounter--;
                scheduleLicenseCheck(delay);
            }
        }
    }, delay);
}

From source file:co.mafiagame.telegraminterface.outputhandler.TelegramChannel.java

@PostConstruct
private void init() {
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    client = HttpClients.createDefault();
    this.url = telegramUrl + telegramToken + "/sendMessage";
    TimerTask timerTask = new TimerTask() {
        @Override//  w  w w.  ja va  2s . c o m
        public void run() {
            SendMessage sendMessage = null;
            try {
                if (!outQueue.isEmpty()) {
                    sendMessage = outQueue.take();
                    deliverMessage(sendMessage);
                }
            } catch (InterruptedException e) {
                logger.error("error in reading outQueue", e);
            } catch (Exception e) {
                logger.error("error sending message " + sendMessage, e);
            }
        }
    };
    Timer timer = new Timer();
    timer.schedule(timerTask, TimeUnit.MINUTES.toMillis(1), TimeUnit.MILLISECONDS.toMillis(200));
}

From source file:ezbake.frack.common.workers.WarehausBatchWorker.java

/**
 * Initializes the warehaus batch worker with required variables.
 * @param props contains ezbake properties.
 */// w ww . jav  a 2 s. c  o m
@Override
public void initialize(Properties props) {
    EzProperties ezProps = new EzProperties(props, true);
    this.maxQueueSize = ezProps.getInteger(BATCH_SIZE_KEY, 50);
    this.pool = new ThriftClientPool(props);
    this.warehausSecurityId = pool.getSecurityId(WarehausServiceConstants.SERVICE_NAME);
    this.putRequest = new PutRequest();
    this.securityClient = new EzbakeSecurityClient(props);
    objects = Lists.newArrayList();
    visibilities = Lists.newArrayList();
    Timer batchWriterTimer = new Timer();
    batchWriterTimer.scheduleAtFixedRate(new WarehausBatchTask(), 0,
            Long.valueOf(props.getProperty("warehouse.batch.timeout", String.valueOf(15000))));
    logger.info("Creating Batch Writer with max queue size of: {}", maxQueueSize);
}