Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Calling a method every 1 or 2 seconds. "Java"

Options
  • 23-04-2006 8:54pm
    #1
    Closed Accounts Posts: 32


    Hey,

    I have a multi-user app where all users can input strings and these strings are sent to a server where they are appended to a text file.

    In the users GUI I have a JTextArea that I want to update every 1 or 2 seconds. I have the method written to read the text file into the JTextArea, but was wondering if there is a way or continously calling this method so it seems like a live update to the user.

    Thnx, if you can understand my jibberish.

    Van


Comments

  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Stick it in a thread.

    Although running a file on disk read every 1-2 seconds is going to cause some serious lag.


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    possibly keep the "file" in memory (unless it's going to get to be 100's of megs...). That'd be much faster and possibly easier to maintain.


  • Registered Users Posts: 763 ✭✭✭Dar


    Or just set it to update on writes only.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    I'm not sure how you've designed it, but seeing as you use the word "server";

    If you've a client-server architecture, then you can "push" the update to the clients instead of having them poll for it. That is, when an update is received, the server notifies all connected clients and sends them the updated text.

    Or, you can use the server as file control. So each client asks the server when the file was last updated, periodically. If the file has been updated, the client requests that the server send it. The server itself will keep the file in memory (assuming it's not huge, as said above), and check the data in memory for integrity every so often (once a minute maybe). This approach would ensure that you're not going to see any performance lag through file reads, even if you've hundreds of clients.


  • Closed Accounts Posts: 32 VanStrummer


    thnx for the help guys.. i'll have a go at your suggestions.

    just to clarify the program:

    its a server which listens on a certain socketm and allows multiple clients to send. all data being recieved over the same socket.

    thnx again

    Van


  • Advertisement
  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Possibly ajax would be the thing to use. It sounds perfect for what you want, but it mightn't be worth the effort of learning.


  • Closed Accounts Posts: 32 VanStrummer


    lol.. ajax was suggested to me by a mate but the project is due in 21 days.

    thnx anyway


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    There are plenty of ways of doing this.

    You could take the IRC approach, and every time a new line is added, you send that new line to every client. The problem there is that some clients can end up with the lines in different orders.
    The main issue with notifying or pushing the data to the clients is that the clients have to be listening too. If the clients only poll the server, then you only have to code a socket listener for the server.

    Best of luck.


Advertisement