Thread: Time Bound Events

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 Time Bound Events 
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    974
    Thanks given
    688
    Thanks received
    455
    Rep Power
    727
    remove
    Reply With Quote  
     

  2. #2  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    RS2 servers still don't have something like this? >.> Astonishes me because a very similar system has existed in matrix since its release and that was a long time ago. RS2 developers need to pick their shit up for real.
    Anyways, it's looking fine, everything seems to be correct. Good job, let's just hope people will actually know how to use it >.>
    Attached image
    Reply With Quote  
     

  3. #3  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    974
    Thanks given
    688
    Thanks received
    455
    Rep Power
    727
    Quote Originally Posted by Kris View Post
    RS2 servers still don't have something like this? >.> Astonishes me because a very similar system has existed in matrix since its release and that was a long time ago. RS2 developers need to pick their shit up for real.
    Anyways, it's looking fine, everything seems to be correct. Good job, let's just hope people will actually know how to use it >.>
    Yeah, every server I worked on hasn't really had a system in place for handling something like this. They usually try to get around it by using process methods or the like.

    Thanks!
    Reply With Quote  
     

  4. #4  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    You could store the events for ease of accessing them, aswell as then calling the run method rather than creating a new instance of the class everytime.
    Also, for duration/timeUnit, you should rather just keep the time as milliseconds or whatsoever and then when you need to receive the time as some sort of TimeUnit just convert it using its inbuilt methods such as:
    Code:
    public TimeUnit getAsMinutes() { 
             return TimeUnit.MILLISECONDS.toMinutes(duration);
      }
    Nonetheless, different versions of this has been released already, but thanks

    (CycleEventHandler/TaskSchedculer, etc, many of these)
    Reply With Quote  
     

  5. #5  
    Renown Programmer & Respected Member

    Ryley's Avatar
    Join Date
    Aug 2011
    Posts
    596
    Thanks given
    254
    Thanks received
    521
    Rep Power
    1332
    reflection at run time, stellar design.
    Reply With Quote  
     

  6. Thankful users:


  7. #6  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    974
    Thanks given
    688
    Thanks received
    455
    Rep Power
    727
    Quote Originally Posted by Tyrant View Post
    Also, for duration/timeUnit, you should rather just keep the time as milliseconds or whatsoever and then when you need to receive the time as some sort of TimeUnit just convert it using its inbuilt methods such as:
    Code:
    public TimeUnit getAsMinutes() { 
             return TimeUnit.MILLISECONDS.toMinutes(duration);
      }
    Why lol? Why would we ever want to create multiple methods for converting milliseconds to minutes / hours / days / seconds when we can just handle it when the class is constructed and convert it using the specified instance of TimeUnit. This makes it much easier to read to. (TimeUnit.Days , 2) instead of whatever 2 days is in milliseconds is rofl.



    Quote Originally Posted by Ryley View Post
    reflection at run time, stellar design.
    Alright well can you educate me as to how this is bad
    Reply With Quote  
     

  8. #7  
    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 Andys1814 View Post
    Why lol? Why would we ever want to create multiple methods for converting milliseconds to minutes / hours / days / seconds when we can just handle it when the class is constructed and convert it using the specified instance of TimeUnit. This makes it much easier to read to. (TimeUnit.Days , 2) instead of whatever 2 days is in milliseconds is rofl.

    Alright well can you educate me as to how this is bad

    Java's documentation on reflection (direct quote)
    Because reflection involves types that are dynamically resolved, certain Java virtual machine optimizations can not be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts, and should be avoided in sections of code which are called frequently in performance-sensitive applications.
    Also, your code is severely flawed in several ways. You're creating a new Timer per event. Every instance of Timer has its own execution thread.

    Look at your schedule method closely, is that _really_ what you intend to do?

    Spoiler for Hint:

    You're passing an instance of ScheduledEvent (which needs to be created) then you create it AGAIN using reflection. Effectively scheduling your event twice.
    Reply With Quote  
     


  9. #8  
    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
    Java's documentation on reflection (direct quote)


    Also, your code is severely flawed in several ways. You're creating a new Timer per event. Every instance of Timer has its own execution thread.

    Look at your schedule method closely, is that _really_ what you intend to do?

    Spoiler for Hint:

    You're passing an instance of ScheduledEvent (which needs to be created) then you create it AGAIN using reflection. Effectively scheduling your event twice.
    Okay it's not like I didn't know reflections was slow. Everyone on this website makes sure they say that on every snippet that includes reflections. I tested it and it takes like 70 ms to load 3 events.

    I knew they operated on a new thread but I completely forgot that it would create a new one for every instance. Thanks


    You're passing an instance of ScheduledEvent (which needs to be created) then you create it AGAIN using reflection. Effectively scheduling your event twice
    I never tested that method so I never caught that. I never tested it because I was hesitant including it anyway considering these eventse have no intention of stopping (and therefore we don't need to reschedule them). Thanks for catching that.

    Thanks though I actually learned from your constructive feedback
    Reply With Quote  
     

  10. Thankful user:


  11. #9  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    [QUOTE=Andys1814;5400223]Why lol? Why would we ever want to create multiple methods for converting milliseconds to minutes / hours / days / seconds when we can just handle it when the class is constructed and convert it using the specified instance of TimeUnit. This makes it much easier to read to. (TimeUnit.Days , 2) instead of whatever 2 days is in milliseconds is rofl.

    I was just saying. besides, if theres no use for TimeUnit theres no reason to create it, and as if its so funny, you wouldnt calculate what 2 days are in milliseconds but rather call TimeUnit.DAYS.toMillis(2)...
    Reply With Quote  
     

  12. #10  
    Donator


    Join Date
    Jul 2013
    Posts
    1,233
    Thanks given
    1
    Thanks received
    493
    Rep Power
    0
    Quote Originally Posted by Ryley View Post
    Also, your code is severely flawed in several ways. You're creating a new Timer per event. Every instance of Timer has its own execution thread.
    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!
    Reply With Quote  
     

Page 1 of 2 12 LastLast

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
  •