0

Example, i have 20 charts. there are have time refresh different. When updateChart, i'll dosomething and update success.

<c:foreach var="chart" items="#{bean.charts}>
  <p:poll interval="#{chart.timeRefresh}" listener="#{bean.updateChart(chart)}"/>
  <div>..draw one-by-one chart here.</div>
</c:foreach>
<p:commandButton id="showInforDialog" actionlistener="#{bean.dosomething()}" onsuccess="PF('dlgInfor').show();"/>

for example, alls chart have same time refresh and equal 1s. when i click button btnStopAllPoll will call dosomething() and will show dialog, but I have to wait a very long time. I think 20 request are processed in turn. i have one idea, create button and onclick will stop all poll i tried :

<p:commandButton id="stoppAllPoll" onclick="stopAllPoll()"/>

but I do not know how to do it. please help me! or you have new idea. i don't understand why 20 request are processed in turn, or I'm wrong

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    PrimeFaces does not have a pool component. There IS a poll component. Regarding the actual question, that is a bit unclear to me can you clarify – Kukeltje Mar 21 '18 at 18:50

1 Answers1

2

First of all, poll Ajax actions are executed synchronically by default. So if you execute 20 actions, they are queued and executed one at a time. That might take a while and explains the delay you are experiencing. Set the async attribute of the p:poll component to true to prevent this.

Then, why use 20 polls in the first place? Isn't is much cleaner to just use 1 poll? You can specify multiple components that need to be updated, even by using a selector. This will also prevent you from running out of the number of connections the client or possibly even the server can handle simultaneously.

If you do want to stop multiple polls, use widgetVar="pollXxx" so you can stop them using JavaScript:

PF('poll1').stop();
PF('poll2').stop();
...
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • Ah... makes sense now. No idea why I missed this. I personally would not even use polling but push and with a small random delay on the client (e.g. if there are many clients watching the charts) update them – Kukeltje Mar 21 '18 at 19:46
  • 1
    Even if you set async to true, most likely you are limited by the number of simultaneous requests a browser can/will do. https://stackoverflow.com/questions/985431/max-parallel-http-connections-in-a-browser – Kukeltje Mar 21 '18 at 19:53
  • Good point. It is far from efficient in many ways. I would opt to simply use one poll and update multiple components. – Jasper de Vries Mar 21 '18 at 20:00
  • in my case, the number of chart is dynamic 10,15,20 or more. there are have time refresh different. ex: chart1: 3s, chart2: 5s, chart3: 10s.... so, i can't just use 1 poll. in here, i'm using of omnifaces. – Trương Huy Mar 22 '18 at 02:09
  • @TrươngHuy your question states "all chart have same time refresh and equal 1s". – Jasper de Vries Mar 22 '18 at 08:06