• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How does Java handles call back listeners ?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is basic for Java, not android. If the code that is inside listener interface does some complex calculations, what happens for callbacks given by the system. In Android, accelerometer readings are collected in onSensorChanged(SensorEvent event). If I want to process "event" data and that its called around 30-40 times a second. What happens ?

Does this reduces the calls to function? Or Does this lags the output but all call will finally get executed ?

I know this should be handled in separate thread, but if large number of threads keep generating , this may be a problem. Also I cannot rely on Java System.currentTimeMillis(); for pinging every say 500 milliseconds as this is never reliable (in a way it guarantees the function will not called before 500 ms but not maximum time like it may be even after 1000 millisecond, which in my case would be a problem as I need data atleast in 500ms). Even if I get 10 out of 30 callbacks , I have no loss for my application.
But can anyone explain what the virtual machine does ?

Or should I consider TimerTask instead for collecting data every 500 ms?
 
If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic