java - Letting a SwingWorker thread sleep -


i have swing gui should read rss feed periodically (the feed provided application wrote). i've implemented in swingworker , want ask if sound design.

here code wrote background method:

@override protected void doinbackground() throws exception {      comboboxmodel.removeallelements();      while(true) {          channel feedchannel = webresource.path(role.role())                                          .accept(mymediatype.application_rss)                                          .get(rss.class).getchannel();          list<item> itemlist = feedchannel.getentrylist();          for(item item : itemlist) {              string itemlink = item.getlink();              if(!feeditemmap.containskey(itemlink)) {                  comboboxmodel.addelement(new pair<>(itemlink, true));                 feeditemmap.put(itemlink, true);             }         }          thread.sleep(10000);     } } 

my idea letting thread sleep reduce number of gets. program doesn't need date every millisecond reduce server load thought idea.

after reading question (java - thread.sleep() within swingworker) i'm confused if idea after all. gathered don't let background thread sleep because system takes care of it.

however in case method seems beneficial me.

can elaborate on possible issues implementation?

any input appreciated. goes specific topic general design. if i'm doing wrong want know it. :)

greetings

use scheduledexecutorservice:

scheduledexecutorservice ses = executors.newsinglescheduledexecutorservice(); ses.scheduleatfixedrate(new runnable() {     @override     public void run() {         doinbackground();     } }, 10, timeunit.seconds); 

and rid of thread.sleep , while(true) loop:

protected void doinbackground() throws exception {     comboboxmodel.removeallelements();     channel feedchannel = webresource.path(role.role())                                      .accept(mymediatype.application_rss)                                      .get(rss.class).getchannel();     list<item> itemlist = feedchannel.getentrylist();     for(item item : itemlist) {         string itemlink = item.getlink();         if(!feeditemmap.containskey(itemlink)) {             comboboxmodel.addelement(new pair<>(itemlink, true));             feeditemmap.put(itemlink, true);         }     } } 

Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -