java - How do I create a new instance of thread multiple times in same program -
i newbie please forgive me if not clear want. have java app inserts 2 mysql tables upon clicking submit, 1 on local machine , other on web server . problem have created 2 threads , 1 each . works fine first time app launched , started , when app running , try insert again clicking submit , not . again when restart app works fine first time . question how stop thread or end , start new instance of , in same instance of app.
am sorry if not clear .
heres code,
final int m = msfuntion.getmemomoc(); thread t1 = new thread(new runnable(){ public void run() { while(runt1){ try{ for(int i=0;i<=jtable2.getrowcount();i++) { object slno= jtable2.getvalueat(i, 1); object item2= jtable2.getvalueat(i, 2); object size2= jtable2.getvalueat(i, 3); string = slno.tostring(); string si = item2.tostring(); int qt = integer.parseint(size2.tostring()); msfuntion.saledetails(m,it, si, qt); //msfuntion.saledetailsweb(m,it, si, qt); sc=0; } }catch(exception e) { e.printstacktrace(); } runt1=false; } } }); thread t2 = new thread(new runnable(){ public void run() { while(runt2){ try{ for(int i=0;i<=jtable2.getrowcount();i++) { object slno= jtable2.getvalueat(i, 1); object item2= jtable2.getvalueat(i, 2); object size2= jtable2.getvalueat(i, 3); string = slno.tostring(); string si = item2.tostring(); int qt = integer.parseint(size2.tostring()); //msfuntion.saledetails(m,it, si, qt); msfuntion.saledetailsweb(m,it, si, qt); sc=0; } }catch(exception e) { e.printstacktrace(); } runt2=false; } t1.start(); t2.start()
it doesn't sound threading issue me. sounds don't commit write or release database connection after write data both tables. depending on how write data database, can happen works 1 thread, not if multiple threads. when run first time, first thread locks database , thread created second write, can't write data because first thread didn't release lock.
one other thing, instead of spawning 2 threads every time clicks button, better use executorservice
Comments
Post a Comment