java - Server Application: Only works with a println output -
apologies ambiguous title - couldn't think how word title.
basically, i'm playing around creating simple server/client programs in java. server runs thread check new connections, if connection found - creates thread , connection object connection.
problem comes in @ thread checks new connections - didn't work, until started error checking , when added in line:
system.out.println(""); it started work should. removing line causes no new threads added connections. assumed providing enough delay thread run or something, put in loop while see if worked - nothing else has worked apart 1 simple line.
here's code creating new connection threads:
class threadcreator implements runnable { threadcreator() { } public void run() { while(true) { system.out.println("why work??"); for(int = 0; < connections.size(); i++) { if(connections.get(i).thread == false) { runnable readrunnable = new read(connections.get(i)); thread readthread = new thread(readrunnable, "mwhahah"); readthread.setpriority(thread.max_priority); readthread.start(); connections.get(i).thread = true; system.out.println("thread created"); } } } } } i can't imagine going wrong..?
one thing keep in mind system.out.println() involves synchronization and call wait() somewhere (since println() out-flushes , waits response visible (or @ least passed other process) until returning.
this can easily "fix" multi-threaded program if synchronization problem.
Comments
Post a Comment