Results 1 to 3 of 3

Thread: Java SE Service

  1. #1
    appdevman is offline Member
    Join Date
    Jun 2010
    Rep Power

    Default Java SE Service

    I wish to create a long running Java SE application

    1. Runs a job at a set interval

    Ex. every 30 seconds write to system.out until application is shutdown.

    Can someone please give me an idea of the best way to accomplish this?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    See the Timer class

  3. #3
    appdevman is offline Member
    Join Date
    Jun 2010
    Rep Power



    I found this to work quite well:

    int initialDelay = 0; // start after 0 seconds
    int period = 5000; // repeat every 5 seconds
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
    public void run() {
    System.out.println("Hello World");
    timer.scheduleAtFixedRate(task, initialDelay, period);

    I was wondering if you could give a recommendation on best practices for structuring this application? Would you recommend putting this timer code right in the main method, or pulling it out into another class?

Similar Threads

  1. how to call service method inside another service
    By kirtichopra2003 in forum Web Frameworks
    Replies: 1
    Last Post: 10-24-2009, 02:19 AM
  2. How to Call a java service
    By omikeneil in forum Advanced Java
    Replies: 3
    Last Post: 10-17-2009, 03:30 AM
  3. Consuming a Web Service using Java
    By gopikrishnatb in forum Web Frameworks
    Replies: 2
    Last Post: 03-02-2009, 09:59 AM
  4. Java Message Service
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 06-09-2008, 09:57 PM
  5. Java Service Wrapper 3.3.0
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 03-29-2008, 01:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts