Note that there are some explanatory texts on larger screens.

plurals
  1. POQueue method or individual db connection?
    primarykey
    data
    text
    <p>I have socket connection which will send data into a queue via <code>databaseQueue.add(message);</code>. Next the the <code>DatabaseProcessor</code> class which is started as thread during the start where single database connection will be made. The connection will keep taking the message via <code>databaseQueue.take();</code> and process. The good part about this part everything is that just one database connection is made. The problem arises when suddenly there is a surge of data. So another method is that for each data received I will open and close method. So based your experiences for heavy loads which is the best way to go here?</p> <p>Some snippet of my codes.</p> <pre><code>class ConnectionHandler implements Runnable { ConnectionHandler(Socket receivedSocketConn1) { this.receivedSocketConn1=receivedSocketConn1; } // gets data from an inbound connection and queues it for databse update public void run() { databaseQueue.add(message); // put to db queue } } class DatabaseProcessor implements Runnable { public void run() { // open database connection createConnection(); while (true) { message = databaseQueue.take(); // keep taking message from the queue add by connectionhandler and here I will have a number of queries to run in terms of select,insert and updates. } } void createConnection() { System.out.println("Crerate Connection"); connCreated = new Date(); try { dbconn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test1?"+"user=user1&amp;password=*******"); dbconn.setAutoCommit(false); } catch(Throwable ex) { ex.printStackTrace(System.out); } } } public void main() { new Thread(new DatabaseProcessor()).start(); //calls the DatabaseProcessor //initiate the socket } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload