Good morning/evening,
I´m implementing a long pooling between client-server by ajax-java. And the long polling works properly on the client side, and every 30 seconds a new connection is throw and the previous one is aborted. But the problem is that in the server side all those request/threads keep alive until we have something to return to the client. But like I said the client maybe is not listening anymore. Here some code:
Client:
// Long Polling (Recommened Technique - Creates An Open Connection To Server ∴ Fast)
(function poll(){
var tenantName = $("#tenantName").val();
$.ajax({
method:"GET",
url: "url",
success: function(data){
if (data === true) {
bootbox.alert("Page has been modify <a href='javascript:void(0)' onclick='reload()'>reload</a>");
}
}, dataType: "json", complete: poll, timeout: 60000 });
})();
Server:
/**
* @return
*/
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public Boolean getSubStepStatus(@RequestParam("subStep") String subStep,
@RequestParam("tenantId") String tenantId) {
if (!isInStep(subStep, tenantId)) {
tenantsInStep.get(subStep).add(tenantId);
}
while (true) {
String modifierTenantId = stepModifyByTenant.get(subStep);
if (modifierTenantId != null && !modifierTenantId.equals(tenantId) && !isInStep(subStep, tenantId)) {
tenantsInStep.get(subStep).remove(tenantId);
return true;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Problem like I said all threads are growing and growing in the server side every 30 seconds, what I´m doing wrong using this technique?
Aucun commentaire:
Enregistrer un commentaire