Thread: Time Bound Events

Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17
  1. #11  
    Server Developer
    Argyros's Avatar
    Join Date
    Apr 2011
    Posts
    498
    Thanks given
    25
    Thanks received
    31
    Rep Power
    23
    Quote Originally Posted by 423 Million View Post
    Wouldn't gc collect the thread's once they finish their task? Also, the amount of threads a modern CPU can handle is pretty high so imo you can negate multiple threads being created for the events -even though ik you should take this into consideration when designing a program. Let me know your thoughts!
    Yes, it would, this is what people don't understand that Java has its own GC and it's better at managing multiple threads, unlike most languages.
    Reply With Quote  
     

  2. #12  
    Renown Programmer & Respected Member

    Ryley's Avatar
    Join Date
    Aug 2011
    Posts
    596
    Thanks given
    254
    Thanks received
    521
    Rep Power
    1332
    Quote Originally Posted by Argyros View Post
    Yes, it would, this is what people don't understand that Java has its own GC and it's better at managing multiple threads, unlike most languages.
    Sure, carelessly write your code cos the GC will clean up after you...

    You would more than likely run out of memory depending on the amount of tasks you have faster than the GC could de-allocate them. There is no reason for you to have such a design and is more problematic than productive.
    Reply With Quote  
     

  3. Thankful users:


  4. #13  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    974
    Thanks given
    688
    Thanks received
    455
    Rep Power
    727
    Quote Originally Posted by Ryley View Post
    Sure, carelessly write your code cos the GC will clean up after you...

    You would more than likely run out of memory depending on the amount of tasks you have faster than the GC could de-allocate them. There is no reason for you to have such a design and is more problematic than productive.
    Wouldn't the garbage collector never actually throw away the threads in my instance considering my program never stops executing functions on them?
    Reply With Quote  
     

  5. Thankful user:


  6. #14  
    Registered Member
    hc747's Avatar
    Join Date
    Dec 2013
    Age
    26
    Posts
    1,474
    Thanks given
    3,312
    Thanks received
    691
    Rep Power
    1098
    Quote Originally Posted by Andys1814 View Post
    Wouldn't the garbage collector never actually throw away the threads in my instance considering my program never stops executing functions on them?
    Correct.
    Reply With Quote  
     

  7. Thankful user:


  8. #15  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    It is worth noting that because you're using a separate thread for these events that any objects you manipulate on this thread that are used on the game thread can create a race condition. The more appropriate solution to your problem would be to extend an already existing event management system and allow it to support the TimeUnit class. You could then submit these tasks on the game thread and process them on the game thread. Of course there can be a slight loss in precision when converting from 'ticks' to real time, but that is the tradeoff.

    I hope you take the time to rewrite this with the constructive criticism from the members of this thread.
    Reply With Quote  
     

  9. Thankful users:


  10. #16  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    974
    Thanks given
    688
    Thanks received
    455
    Rep Power
    727
    Quote Originally Posted by Jason View Post
    It is worth noting that because you're using a separate thread for these events that any objects you manipulate on this thread that are used on the game thread can create a race condition. The more appropriate solution to your problem would be to extend an already existing event management system and allow it to support the TimeUnit class. You could then submit these tasks on the game thread and process them on the game thread. Of course there can be a slight loss in precision when converting from 'ticks' to real time, but that is the tradeoff.

    I hope you take the time to rewrite this with the constructive criticism from the members of this thread.
    I initially thought of doing this and I'm not sure why I didn't go with it in the first place. I had this idea in my thread that I wanted to do and I went for it even knowing the issues that came alongside it.

    I'll definitely be redoing it at some point and may repost it.
    Reply With Quote  
     

  11. Thankful user:


  12. #17  
    Server Developer
    Argyros's Avatar
    Join Date
    Apr 2011
    Posts
    498
    Thanks given
    25
    Thanks received
    31
    Rep Power
    23
    Quote Originally Posted by Ryley View Post
    Sure, carelessly write your code cos the GC will clean up after you...

    You would more than likely run out of memory depending on the amount of tasks you have faster than the GC could de-allocate them. There is no reason for you to have such a design and is more problematic than productive.
    That's what the GC is for, it's a lot harder to have memory leaks in Java because of the GC, a competent JVM will have no leaks period.
    Only time you really need to worry about stuff like this is when you try and hold a reference to objects that are no longer are needed which in this case can cause a memory leak. (But you should already know this)
    The object is already loaded in the JVM so soon as it dies the GC will just clean it out, but you're correct it should be given on how well you code, but for most programs, the GC will always do its job.
    Reply With Quote  
     

Page 2 of 2 FirstFirst 12

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 10
    Last Post: 11-06-2010, 04:13 AM
  2. Replies: 18
    Last Post: 08-15-2010, 09:16 AM
  3. Replies: 13
    Last Post: 07-19-2010, 11:32 PM
  4. Timed Server Announcements [EVENTS]
    By Flux in forum Tutorials
    Replies: 17
    Last Post: 07-11-2010, 02:25 PM
  5. Best way to make a "Timed Event"
    By Zahhak in forum Help
    Replies: 4
    Last Post: 03-17-2010, 08:03 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •