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(String name) 

Source Link

Document

Creates a new timer whose associated thread has the specified name.

Usage

From source file:com.microsoft.tfs.client.common.ui.controls.connect.CrossCollectionProjectSelectControl.java

public CrossCollectionProjectSelectControl(final Composite parent, final int style,
        final SourceControlCapabilityFlags sourceControlCapabilityFlags) {
    super(parent, style);

    final GridLayout layout = new GridLayout();
    layout.marginWidth = 0;/*from www .  jav a2  s  . c o  m*/
    layout.marginHeight = 0;
    layout.horizontalSpacing = getHorizontalSpacing();
    layout.verticalSpacing = getVerticalSpacing();
    setLayout(layout);

    // Create timer for filtering the list
    filterTimer = new Timer(false);

    // Create the filter text box
    filterBox = new Text(this, SWT.BORDER);
    filterBox.setMessage(Messages.getString("CrossCollectionProjectSelectControl.FilterHintText")); //$NON-NLS-1$
    filterBox.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            startTimer();
        }
    });
    GridDataBuilder.newInstance().hGrab().hFill().applyTo(filterBox);

    table = new CrossCollectionProjectTable(this, SWT.NONE, false);
    table.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            ((ProjectSelectionChangedListener) listeners.getListener())
                    .onProjectSelectionChanged(new ProjectSelectionChangedEvent(table.getSelectedProject()));
        }
    });
    GridDataBuilder.newInstance().grab().hHint(getVerticalSpacing() * 30).fill().applyTo(table);
}

From source file:io.aino.agents.core.Agent.java

private Agent(AgentConfig config) {
    agentConfig = config;//from   w  w  w . j  a v  a  2  s .c  om

    senderThreads = new HashMap<Thread, Sender>();

    dataBuffer = new TransactionDataBuffer(agentConfig.getSizeThreshold());
    Sender sender = new Sender(agentConfig, dataBuffer);
    senderThreads.put(new Thread(sender), sender);

    validators = new ArrayList<TransactionValidator>();
    validators.add(new OperationValidator(agentConfig));
    validators.add(new IdTypeValidator(agentConfig));
    validators.add(new ApplicationValidator(agentConfig));

    overloadCheckerTimer = new Timer(true);
    overloadCheckerTimer.schedule(new SenderOverloadCheckerTask(this, dataBuffer, agentConfig), 5000, 5000);

    if (isEnabled()) {
        log.info("Aino logger is enabled, starting sender thread.");
        for (Map.Entry<Thread, Sender> thread : senderThreads.entrySet()) {
            thread.getKey().start();
        }
    }
    log.info("Aino logger initialized.");
}

From source file:org.mobicents.servlet.restcomm.Ping.java

public void sendPing() {
    boolean daemon = true;
    timer = new Timer(daemon);
    ping = new PingTask(configuration);
    timer.schedule(ping, 0, 60000);/*  www . jav a2 s  . c o m*/
}

From source file:com.mtnsat.testcode.StopWatch.java

public void running() {
    split = false;//w w w.  j  ava  2s  .c o m
    if (timer == null) {
        timer = new Timer(true);
        timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                increment();
            }
        }, 100, 100);
    }
}

From source file:fr.gouv.culture.vitam.utils.Executor.java

/**
 * Execute an external command/*from w w w.  ja  va 2  s  . c om*/
 * @param cmd
 * @param tempDelay
 * @param correctValues
 * @param showOutput
 * @param realCommand
 * @return correctValues if ok, < 0 if an execution error occurs, or other error values
 */
public static int exec(List<String> cmd, long tempDelay, int[] correctValues, boolean showOutput,
        String realCommand) {
    // Create command with parameters
    CommandLine commandLine = new CommandLine(cmd.get(0));
    for (int i = 1; i < cmd.size(); i++) {
        commandLine.addArgument(cmd.get(i));
    }
    DefaultExecutor defaultExecutor = new DefaultExecutor();
    ByteArrayOutputStream outputStream;
    outputStream = new ByteArrayOutputStream();
    PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(outputStream);
    defaultExecutor.setStreamHandler(pumpStreamHandler);

    defaultExecutor.setExitValues(correctValues);
    AtomicBoolean isFinished = new AtomicBoolean(false);
    ExecuteWatchdog watchdog = null;
    Timer timer = null;
    if (tempDelay > 0) {
        // If delay (max time), then setup Watchdog
        timer = new Timer(true);
        watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
        defaultExecutor.setWatchdog(watchdog);
        CheckEndOfExecute endOfExecute = new CheckEndOfExecute(isFinished, watchdog, realCommand);
        timer.schedule(endOfExecute, tempDelay);
    }
    int status = -1;
    try {
        // Execute the command
        status = defaultExecutor.execute(commandLine);
    } catch (ExecuteException e) {
        if (e.getExitValue() == -559038737) {
            // Cannot run immediately so retry once
            try {
                Thread.sleep(100);
            } catch (InterruptedException e1) {
            }
            try {
                status = defaultExecutor.execute(commandLine);
            } catch (ExecuteException e1) {
                pumpStreamHandler.stop();
                System.err.println(StaticValues.LBL.error_error.get() + "Exception: " + e.getMessage()
                        + " Exec in error with " + commandLine.toString() + "\n\t" + outputStream.toString());
                status = -2;
                try {
                    outputStream.close();
                } catch (IOException e2) {
                }
                return status;
            } catch (IOException e1) {
                pumpStreamHandler.stop();
                System.err.println(StaticValues.LBL.error_error.get() + "Exception: " + e.getMessage()
                        + " Exec in error with " + commandLine.toString() + "\n\t" + outputStream.toString());
                status = -2;
                try {
                    outputStream.close();
                } catch (IOException e2) {
                }
                return status;
            }
        } else {
            pumpStreamHandler.stop();
            System.err.println(StaticValues.LBL.error_error.get() + "Exception: " + e.getMessage()
                    + " Exec in error with " + commandLine.toString() + "\n\t" + outputStream.toString());
            status = -2;
            try {
                outputStream.close();
            } catch (IOException e2) {
            }
            return status;
        }
    } catch (IOException e) {
        pumpStreamHandler.stop();
        System.err.println(StaticValues.LBL.error_error.get() + "Exception: " + e.getMessage()
                + " Exec in error with " + commandLine.toString() + "\n\t" + outputStream.toString());
        status = -2;
        try {
            outputStream.close();
        } catch (IOException e2) {
        }
        return status;
    } finally {
        isFinished.set(true);
        if (timer != null) {
            timer.cancel();
        }
        try {
            Thread.sleep(200);
        } catch (InterruptedException e1) {
        }
    }
    pumpStreamHandler.stop();
    if (defaultExecutor.isFailure(status) && watchdog != null) {
        if (watchdog.killedProcess()) {
            // kill by the watchdoc (time out)
            if (showOutput) {
                System.err.println(StaticValues.LBL.error_error.get() + "Exec is in Time Out");
            }
        }
        status = -3;
        try {
            outputStream.close();
        } catch (IOException e2) {
        }
    } else {
        if (showOutput) {
            System.out.println("Exec: " + outputStream.toString());
        }
        try {
            outputStream.close();
        } catch (IOException e2) {
        }
    }
    return status;
}

From source file:de.jwic.base.SessionManager.java

/**
 * Default Constructor.//from  w  w  w .ja v  a 2  s  .com
 */
public SessionManager(String tempDir) {
    serDir = new File(tempDir);
    if (!serDir.exists()) {
        serDir.mkdirs();
    }

    timer = new Timer(true);
    timer.schedule(new RefreshDeamon(), DELAY, INTERVALL);
}

From source file:com.github.matthesrieke.simplebroker.AbstractConsumer.java

private void startWatchThread() {
    this.timerDaemon = new Timer(true);
    this.timerDaemon.scheduleAtFixedRate(new CheckFile(TRUSTED_HOSTS_CFG_FILE, new LocalCallback()), 0L,
            60000L);/*  www.jav  a 2s  .  c  o m*/
}

From source file:mastermind.RandomGenerator.java

private RandomGenerator() {
    isValid = true;//from  w  w  w.j  a  v a 2s  . c o  m
    try {
        secureRandom = SecureRandom.getInstance(SECURE_RANDOM_ALGORITHM, SECURE_RANDOM_PROVIDER);
    } catch (NoSuchAlgorithmException nsle) {
        isValid = false;
    } catch (NoSuchProviderException nspe) {
        isValid = false;
    }
    random = new Random(System.currentTimeMillis());
    seedTimer = new Timer(true); // Daemon-Thread
}

From source file:FileMonitor.java

protected FileMonitor() {
    // Create timer, run timer thread as daemon.
    timer = new Timer(true);
    timerEntries = new Hashtable<String, FileMonitorTask>();
}

From source file:com.betfair.tornjak.monitor.DefaultMonitor.java

public DefaultMonitor() {
    timer = new Timer(true);
}