Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Class to run in future!

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Class to run in future!

    Hello!

    I am using servlets in Web Server and I need advice on how to do something I need...

    I need to have a calendar in a servlet webpage with time and date and I need to do an action on a data and time specified by the user...

    How can I do this?? After setting the date and time what is the easiest option??

    Get the time at the moment and the future time, make the difference and run a thread till reaches 0 and then call a certain class??

    Get the future time and keep checking the current time on a thread??

    Thanks


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Class to run in future!

    Hello, if I understand this correctly I'd say you should have all your actions created and then have a job/thread running on you server that checks the actions every 10 minutes or whatever your requirement might be. If an action is due to be run you run it.

    // Json

  3. #3
    Junior Member
    Join Date
    May 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Class to run in future!

    Hi!

    Thanks for your answer.

    The action I want to to is set to a certain day at a certain time.

    Example: On a webpage the user sets a day and time to do the action. At that day and time, the server executes the action. I just need to call a function.

    My doubt is how can I achieve this...

    After the user sets date and time should I start a thread?? The thread will keep checking current date and time.

  4. #4
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Class to run in future!

    Like I said before, I think you should start a thread when you start your web application. This thread could then run all the time and every minute or so just look at the list of actions and if the current time is after the time to run the action, then run it.

    // Json

  5. #5
    Junior Member
    Join Date
    May 2010
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Class to run in future!

    You can use Timer API to schedule your task on time provided by the user.Timer (Java 2 Platform SE v1.4.2)

Similar Threads

  1. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM
  2. problem with data access when a class call another class
    By ea09530 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2010, 05:20 PM
  3. Future of Java
    By Skynet.Boy in forum Java Theory & Questions
    Replies: 4
    Last Post: March 15th, 2010, 09:12 AM
  4. how to load a class and type cast to that class?
    By chinni in forum Object Oriented Programming
    Replies: 2
    Last Post: November 9th, 2009, 10:18 AM
  5. Replies: 5
    Last Post: October 15th, 2009, 08:54 PM