I am trying to make a chat, something similar to what is on facebook.
I need to check if a user received a message from an other one. My first approach was to do a query in ajax every 3 seconds but that's bad so I am changing in order to do a query passing a timestamp. I do an infinite loop where I check the last modification date of the file where I write the conversation of the chat and if the last modification date is greater than the timestamp of the query I then stop the loop and send the result. My problem is that the application becomes completely unresponsive. Any idea what I can do?
Here is the code with the loop:
boolean isNewMessage = false;
List<User> users = new ArrayList<User>();
String files = dir.list();
String tmp = file.split("_");
File f = new File(file);
isNewMessage = true;
Can you help with this problem?
Provide an answer of your own, or ask marc for more information if necessary.