can I control the refresh rate of a Java listener? -



can I control the refresh rate of a Java listener? -

i'm struggling issue since days ago , i'm not able find solution. have listener receives market info (orders @ bid , ask). if market quiet (pre-market or post-market (low volatility)) works fine. 1 time market open listener receives events fast. after couple of minutes app freezes. right listener assigns received info var.

orderbookbid.getbuyorders().addlistener(new observablelistmodellistener<order>() { @override public void modelchanged(final change<? extends order> change) { system.out.println("bid event"); bidchange = change.getsource(); } });

the programme freezes when uses real data. when market closed , uses test info local file works fine.

is there way set maximum number of events per second? or way ignore events short time period? thought on how can handle appreciated.

thanks.

you set load balancer in application, way create queue , not freeze application.

if want allow go events, in logic of listener, should have check if it's been x time since lastly time managed event.

private long timesincelasteventmanaged = 0; private final static long minimum_time = 2000; //2 seconds

in listener

public void modelchanged(final change<? extends order> change) { long timesystem = system.currenttimemillis(); if(timesystem - timesincelasteventmanaged > minimum_time){ //do stuff timesincelasteventmanaged = timesystem; } }

java listener

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -