Results 1 to 4 of 4
  1. #1
    yma16 is offline Member
    Join Date
    Apr 2011
    Posts
    52
    Rep Power
    0

    Default A question about the TimerTask class

    In run() method of the TimerTask class, I need to modify an array. But run() is void. How can I get the array after the change?

    This question is related the project I posted a few days ago call "Program for the store"

    Thank you very much.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You might wish to respond to the good folks who helped you in the previous thread. :)
    Last edited by Fubarable; 05-06-2011 at 04:12 AM.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Sorry, I wasn't clear. Just a simple thanks for replying was what I meant, something to acknowledge that you read their post and appreciate the time they took to consider your problem and try to help you.

    Any way regarding your problem, TimerTask will need to be extended to be used, and often this is done as an anonymous inner class. Its run method's signature cannot be changed, and so this method will never return anything, but that's OK, since you'll never call it directly and so you really don't want it to return anything. Rather, you'll likely have it changing the state of either fields it holds, or more likely (if it is being used as an anonymous inner class) of fields held by the containing class.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,453
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    Any way regarding your problem, TimerTask will need to be extended to be used, and often this is done as an anonymous inner class. Its run method's signature cannot be changed, and so this method will never return anything, but that's OK, since you'll never call it directly and so you really don't want it to return anything. Rather, you'll likely have it changing the state of either fields it holds, or more likely (if it is being used as an anonymous inner class) of fields held by the containing class.
    In the java.util.concurrent package there's the Future interface (with a FutureTask implementation). It does exactly what the OP wants. That package should be used more ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. TimerTask for each value of array
    By lexikovs in forum New To Java
    Replies: 5
    Last Post: 04-02-2011, 09:16 PM
  2. thread + timertask
    By anra in forum Threads and Synchronization
    Replies: 0
    Last Post: 03-08-2011, 10:05 AM
  3. hibernate session = null in the run() method of TimerTask
    By fabs in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-17-2009, 03:12 PM
  4. Timer and TimerTask
    By AndrewM16921 in forum New To Java
    Replies: 2
    Last Post: 04-07-2009, 11:40 PM
  5. TimerTask with a Date_Time
    By kunta in forum Sun Java Wireless Toolkit
    Replies: 1
    Last Post: 05-31-2007, 10:17 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
  •