Results 1 to 1 of 1
Thread: Is this a suitable architecture?
- 03-03-2012, 04:16 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 19
- Rep Power
- 0
Is this a suitable architecture?
We tested a socket connection programme with the idea where the socket connection will be one separate thread by itself and then it will enqueue and another separate thread for dbprocessor will pick from the queue and run through a number of sql statement. So I notice here is where the bottle neck that the db processing. I would like to get some idea is what I am doing the right architecture or I should change or improve on my design flow? Beside that there are two more thread which will do the sms and email task.
The requirement is to capture data via socket connections and run through a db process then store it accordingly.
Java Code:public class cServer { private LinkedBlockingQueue<String> databaseQueue = new LinkedBlockingQueue<String>(); 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&password=*******"); dbconn.setAutoCommit(false); } catch(Throwable ex){ ex.printStackTrace(System.out); } } } public void main() { new Thread(new DatabaseProcessor()).start(); //calls the DatabaseProcessor try { final ServerSocket serverSocketConn = new ServerSocket(9000); while (true){ try{ Socket socketConn1 = serverSocketConn.accept(); new Thread(new ConnectionHandler(socketConn1)).start(); } catch(Exception e){ e.printStackTrace(System.out); } } } catch (Exception e){ e.printStackTrace(System.out); } } }
Similar Threads
-
No suitable driver found
By chinna in forum New To JavaReplies: 3Last Post: 11-30-2011, 01:17 PM -
No suitable driver found
By geekchick in forum New To JavaReplies: 2Last Post: 08-25-2010, 12:12 AM -
What layoutmanager is suitable for forms.
By Somelauw in forum AWT / SwingReplies: 9Last Post: 12-05-2009, 01:04 PM -
Which is the most suitable IDE ?
By javaamateur in forum NetBeansReplies: 2Last Post: 10-11-2009, 11:21 AM -
What database is more suitable to a java app?
By hittite in forum New To JavaReplies: 6Last Post: 11-14-2008, 04:33 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks