Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle wait() notify()?
    primarykey
    data
    text
    <p>Here I have two run methods which should synchronize each other.</p> <p>Poller Class:</p> <pre><code> */ public void run() { int seqId = 0; while(true) { List&lt;KpiMessage&gt; list = null; try{ if(!accumulator.isUsed){ try { list = fullPoll(seqId); if (!list.isEmpty()) { seqId = list.get(0).getSequence(); accumulator.manageIngoing(list); } System.out.println("Updated"); wait(); } catch (Exception e1) { e1.printStackTrace(); } } } catch (Exception e){ // TODO: System.err.println(e.getMessage()); e.printStackTrace(); } } } /** * Method which defines polling of the database and also count the number of Queries * @param lastSeq * @return pojo col * @throws Exception */ public List&lt;KpiMessage&gt; fullPoll(int lastSeq) throws Exception { Statement st = dbConnection.createStatement(); System.out.println("Polling"); ResultSet rs = st.executeQuery("Select * from msg_new_to_bde where ACTION = 814 and STATUS = 200 order by SEQ DESC"); List&lt;KpiMessage&gt; pojoCol = new ArrayList&lt;KpiMessage&gt;(); try { while (rs.next()) { KpiMessage filedClass = convertRecordsetToPojo(rs); pojoCol.add(filedClass); } for (KpiMessage pojoClass : pojoCol) { System.out.print(" " + pojoClass.getSequence()); System.out.print(" " + pojoClass.getTableName()); System.out.print(" " + pojoClass.getAction()); System.out.print(" " + pojoClass.getKeyInfo1()); System.out.print(" " + pojoClass.getKeyInfo2()); System.out.print(" "+ pojoClass.getStatus()); System.out.println(" " + pojoClass.getEntryTime()); } } finally { try { st.close(); rs.close(); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } } </code></pre> <p>Processing and Updating Class:</p> <pre><code> public void run() { while(true){ try { while(!accumulator.isUsed) { try { System.out.println("Waiting for new outgoingmessages"); this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } Collection&lt;KpiMessage&gt; outgoingQueue = generate(accumulator.outgoingQueue); accumulator.manageOutgoing(outgoingQueue, dbConnection); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } } } } </code></pre> <p>I have a logical error:</p> <p>The poller is polling not only for new messsage but also reads the DB again and again from the first.</p> <p>Also Updates again and again.</p> <p><strong>How to solve this synchronization problem</strong>.</p>
    singulars
    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.
 

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