Polling best practices

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
LordDawn
Posts: 42
Joined: 15 Apr 2019, 08:36

Polling best practices

Postby LordDawn » 10 May 2019, 07:15

I want to create an update method that is called 12 times per second, what would be the best practice for this?

Currently I'm using this for a 5 minute task, but is it still the best method for a 12 times per second task, or should I use a thread with a thread-sleep in it, or is there a better method still?

Code: Select all

      m_taskHandle = sfs.getTaskScheduler().scheduleAtFixedRate(new MyScheduler(), 0, 300, TimeUnit.SECONDS);


Many thanks.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Polling best practices

Postby Lapo » 10 May 2019, 07:27

Hi,
yes you can use a scheduler task set to 83 milliseconds (1000/12)

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
LordDawn
Posts: 42
Joined: 15 Apr 2019, 08:36

Re: Polling best practices

Postby LordDawn » 10 May 2019, 07:32

Cool, thanks Lapo.

And it's still performant to use "new <class>" in the scheduleAtFixedRate, creating and destroying class instances that fast?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Polling best practices

Postby Lapo » 10 May 2019, 07:40

There's no other way :D
Unless you want to pool and reuse objects, there's nothing inherently wrong with creating new objects relatively fast. (80 msec intervals are not that fast, a for loop is much faster :D ). Unless these objects have a very high cost of instantiation, in which case pooling might be a consideration.

But, again, generally speaking, it's just fine to use new

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 103 guests