java - JavaFX : Supply arguments to Task -


i working on javafx project in making network calls task. unfortunately, have not been able find how can pass arguments it. have searched many links, none of them provides. 1 link java2s claims passing, code not reflect that.

as can see code below, using for-loop , passing id parameter of restgroupaccount in url. time it's okay because anyways need of restcanvas.

but interested in knowing how give parameters task

code :

private task<list<restcanvas>> fetchcanvases = new task<list<restcanvas>>() {      @override     protected list<restcanvas> call() throws exception {         list<restcanvas> list = new arraylist<>();         try{             for(restgroupaccount groupaccount : groupaccounts) {                 resttemplate rest = staticresttemplate.getrest();                 httpheaders requestheaders = new httpheaders();                 requestheaders.add("cookie", "jsessionid=" + staticresttemplate.jsessionid);                 httpentity<restcanvas> requestentity = new httpentity<>(requestheaders);                 rest.getmessageconverters().add(new mappingjackson2httpmessageconverter());                 rest.getmessageconverters().add(new mappingjackson2httpmessageconverter());                 responseentity<restcanvas[]> responseentity = rest.exchange(getcanvasforgroupaccount+groupaccount.getgroupid(), httpmethod.get, requestentity, restcanvas[].class);                 restcanvas[] restcanvasarray = responseentity.getbody();                 collections.addall(list, restcanvasarray);             }         }catch (exception e){             e.printstacktrace();         }          return list;     } }; 

if more information required, kindly let me know. thank you.

if need use code inside task more once, should consider creating non-anonymous subclass , instantiate every time need construction parameter.

in example might be:

private task<list<restcanvas>> fetchcanvases = new mytask(getcanvasforgroupaccount + groupaccount.getgroupid());  // ...  // please don't use name :) private static class mytask extends task<list<restcanvas>> {     private final string id;      public mytask(string id) {         this.id = id;     }      @override     protected list<restcanvas> call() throws exception {         list<restcanvas> list = new arraylist<>();         try{             for(restgroupaccount groupaccount : groupaccounts) {                 resttemplate rest = staticresttemplate.getrest();                 httpheaders requestheaders = new httpheaders();                 requestheaders.add("cookie", "jsessionid=" + staticresttemplate.jsessionid);                 httpentity<restcanvas> requestentity = new httpentity<>(requestheaders);                 rest.getmessageconverters().add(new mappingjackson2httpmessageconverter());                 rest.getmessageconverters().add(new mappingjackson2httpmessageconverter());                 responseentity<restcanvas[]> responseentity = rest.exchange(id, httpmethod.get, requestentity, restcanvas[].class);                 restcanvas[] restcanvasarray = responseentity.getbody();                 collections.addall(list, restcanvasarray);             }         }catch (exception e){             e.printstacktrace();         }           return list;     } } 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -