Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Instance variable in multiple swing worker thread with thread-safe?
    primarykey
    data
    text
    <p>I am using swing worker thread to communicate rest services. My scenerio is i am calling one thread to get the data from rest services and add into my list variable . and another one thread to push the list of data to save it. How to handle this scenerio with thread safe</p> <p>My sample code is below</p> <pre><code> private LinkedList&lt;LinkInfo&gt; ***linkInfoList*** = new LinkedList&lt;FlowLinkEntry&gt;(); SwingWorker&lt;LinkInfo, Void&gt; loadLinkInfoThread = new SwingWorker&lt;LinkInfo, Void&gt;() { @Override protected LinkInfo doInBackground() throws Exception { InputStream is = new URL("Http://URL").openStream(); try { BufferedReader reader = new BufferedReader( new InputStreamReader(is, Charset.forName("UTF-8"))); LinkInfo linkInfo = (LinkInfo)JsonConverter .fromJson(reader, LinkInfo.class); ***linkInfoList*** .add(linkInfo); } finally { is .close(); } return linkInfo; } } SwingWorker&lt;Void, Void&gt; saveLinkInfoThread = new SwingWorker&lt;Void, Void&gt;() { @Override protected Void doInBackground() throws Exception { //post data to particular url //linkInfoList data is posting in this thread URL url = new URL(http://url); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(***linkInfoList*** ); wr.flush(); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader( conn.getInputStream())); } </code></pre> <p>}</p> <p>My questions are </p> <ol> <li><p>How to store the data in linkInfoList as request order wise? (ie) if i call load thread several time,the data should inserted in list request wise.</p></li> <li><p>How to put wait state the save Thread if load Thread is already in progress. I mean that if load thread is in running condition, after completing load thread then only save thread should have to run </p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload