hi, i developed a client server program in which the client sending messages selected from oracle DB to server and getting back the response...iam using two threads 1 for readin DB values 2 nd to send to client.this i have to configure for a particular time ...ie; if i configure it for send 13 message in 1 sec it should send accordinly and if i configure it for 15 it should send 15 message in a second ...what will i do for that..i am pasting my pgm here please anybody help... ------------------- //server TCPServer.java import java.io.*; import java.net.*;
class TCPServer { public static void main(String[] args) { try {
ServerSocket welcomeSocket = new ServerSocket(8003);
while (true) { System.out.println("time to get connection socket-->"+System.currentTimeMillis()); Socket connectionSocket = welcomeSocket.accept(); System.out.println(" connected to " +connectionSocket.getInetAddress() + ":" +connectionSocket.getPort());
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); DataOutputStream outToClient =new DataOutputStream(connectionSocket.getOutputStream());
String clientSentence = inFromClient.readLine();
while (clientSentence != null) { System.out.println(" -- " + clientSentence);
class reading extends Thread//--thread to read from DB { public int m; public static Collection dbList = null; static String c1; static String c2; public static int w;//--number of rows ResultSet rs;
public static Collection collect;//--linklist
public synchronized void run() {
System.out.println("reading1................."); dbList= new LinkedList(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con; con=DriverManager.getConnection("Jdbc:Odbc:myoracle","scott","tiger"); Sta tement stmt = con.createStatement ();
String query = "select MESSAGEID from s1 where ROWNUM<=13 and MESSAGESTATUS=0";//13==> number of msg need to send within a second rs=stmt.executeQuery(query);
while (rs.next()) { w = rs.getRow(); c1=rs.getString("MESSAGEID"); dbList.add(c1);
}
con.close(); li st(dbList); } catch(Exception e) {System.out.println("This is exception"+e);}
} void list(Collection dbList)//--to get the link list in sending { collect=dbList;//-- link list copy System.out.println("collect====>"+collect); } }
class sending extends reading { public static int m; public static Collection dbList = null;//--linklist static String c1; static String c2; public static int w; static ResultSet rs; static ResultSet rs1;
void sending1() throws Exception { System.out.println("..............sending1"); Socket clientSocket = new Socket("192.9.200.61", 8003); DataOutputStream outToServer =new DataOutputStream(clientSocket.getOutputStream()); BufferedReader inFromServer =new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); System.out.flush(); String line = "dddd"; for(;;)//for infinite loop for continuously taking value from db { Iterator itr=(collect).iterator(); Object element= itr.next(); line =element.toString();
for(;(itr.hasNext());)//to take from link list { element= itr.next(); line=element.toString(); outToServer.writeBytes(line + '\n'); String modifiedSentence = inFromServer.readLine(); System.out.println("Modified: " + modifiedSentence);
System.out.flush(); String query = "update s1 set MESSAGESTATUS='1', senddatetime =sysdate where MESSAGEID="+modifiedSentence;//--after sending change db dbconnection db=new dbconnection(query);//--DB connection System.out.flush(); itr.remove(); collect.remove(0);//--remove from link list System.out.println("collect after sending==>"+collect); }
class TCPClient extends Thread { public static int m; public static Collection dbList = null; static String c1; static String c2; public static int w; static ResultSet rs; public static int loadMsgs;
public static void main(String args[]) throws Exception {