Results 1 to 7 of 7
  1. #1
    ForeverP is offline Member
    Join Date
    Apr 2011
    Posts
    14
    Rep Power
    0

    Default 2 Java Programs Interacting Same Computer

    Okay so I'll ATTEMPT to explain this thoroughly because I desperately need help!

    I have an online game running on Java on a server with many players on it, and I want to have HighScores for the game using MySQL. When I run a query to connect to the MySQL, it temporarily 'lags' (delays) the server for roughly 5 seconds while it connects. It connects about once every minute or two. This is a BIG deal for my game. It can't do that.

    So, what I thought of doing, is having a slave Java program to do all the MySQL work, so it will only delay the slave and not the master server. They will both be running on the same computer, though.

    Does anyone have any idea how I'd go about doing this?

    I don't even need to return the variable to the master server, just have the master server send a command to the slave to do the MySQL. This is because I want to have the player's stats on the online game uploaded to the MySQL data table so it can be displayed on the website.

    Any help is appreciated, thanks in advance.

    Edit: Am I thinking too hard? For MySQL can I just use http post..? I just read about and it seems I can just be like, example pseudo: connect(website.com/sql.php?hs1=1&hs2=1) or something along those lines then have it add it to the database and that will not cause any lag?
    Last edited by ForeverP; 06-19-2011 at 05:57 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    When I run a query to connect to the MySQL, it temporarily 'lags' (delays) the server for roughly 5 seconds while it connects.
    That sounds odd. As with any operation that is going to take a while the program should use a new thread for anything that is going to take a while and which does not materially affect its operation.

    Also couldn't the server just reuse the same connection over and over again as needed?

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by pbrockway2 View Post
    That sounds odd. As with any operation that is going to take a while the program should use a new thread for anything that is going to take a while and which does not materially affect its operation.

    Also couldn't the server just reuse the same connection over and over again as needed?

    because of safety considerations i think having a connection from a game directly to a mysql server is not a good idea. so i would try to transmit the score in a encrypted file to the server. on the server a thread is running checking for new files and inserting it in the db table.

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default

    Personally I'd use a separate thread within the main program to do all the SQL-commands, if they lag you out that much. I'm unsure if named pipes work with Java, but one way you could communicate between two programs would be to use sockets; make a serversocket in one of the programs and connect to it from the other program. That's probably trying to shoot mosquitos with a cannon though; a thread would do the job just as splendidly.

  5. #5
    ForeverP is offline Member
    Join Date
    Apr 2011
    Posts
    14
    Rep Power
    0

    Default

    The game client connects to the game server which is on a different host..
    And yes it lags the entire game, to where all the players are just standing there not moving or doing anything until it connects and gets the data.

    Also, no, it cannot just connect once. I thought that was the case, but I think the MySQL connection disconnects every minute or two, because it starts to error if I don't reconnect after a while.

    How would I go about making a different thread for an operation? I've never heard of doing that

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by ForeverP View Post
    How would I go about making a different thread for an operation? I've never heard of doing that
    for example using socket connection.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Quote Originally Posted by ForeverP View Post
    Also, no, it cannot just connect once. I thought that was the case, but I think the MySQL connection disconnects every minute or two, because it starts to error if I don't reconnect after a while.
    Have you thought about using a connection pool if you're encountering these problems with your connection?
    That would handle all the reconnecting in the background (during its keep alive operation).
    You'd only need a handful.

Similar Threads

  1. Websites for java programs?
    By Phoenix Dogstar in forum Forum Lobby
    Replies: 1
    Last Post: 05-03-2011, 05:11 AM
  2. Java Computer Shop Help (Please)
    By acash229 in forum New To Java
    Replies: 2
    Last Post: 01-27-2011, 08:39 PM
  3. Two simple programs interacting
    By 1sprit in forum New To Java
    Replies: 3
    Last Post: 12-29-2010, 01:16 AM
  4. Oracle trigger interacting with Java app
    By KentDMc in forum Advanced Java
    Replies: 1
    Last Post: 04-27-2009, 01:49 AM
  5. Interacting with the Java Garbage Collector
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-28-2008, 08:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •