I'm currently doing my assignment, which is a client, server network application. A concurrent server.
Its a concurrent server, and works perfectly for general communication. However i have to store how many times the file has been 'downloaded'.
The server works by creating a thread upon a successful connection. The server then has to print out how many times a file has been downloaded after its downloaded.
The thread when a file is downloaded calls a method in the server to increment the download count. However because its seperate threads when multiple clients connect it doesnt increment the updated number that another client might have set.
Output from my IDE to show what i mean:
Waiting for connection request...
Creating a new thread
Number of threads running: 1
Waiting for connection request...
File 1 has been downloaded 1 times.
Creating a new thread
Number of threads running: 2
Waiting for connection request...
File 1 has been downloaded 1 times.
Obviously File 1 should have been downloaded 2 times.
Nice rant!
Expletive after expletive after expletive.
Poor petal, I've touched a nerve. Would you like a tissue to wipe those tears away.
Btw, nice one calling Neowin trash. Why would you stick around when you disrespect this site and the people behind it? Just go away if you feel that way.
Question
+dave164 Subscriber¹
Hey,
I'm currently doing my assignment, which is a client, server network application. A concurrent server.
Its a concurrent server, and works perfectly for general communication. However i have to store how many times the file has been 'downloaded'.
The server works by creating a thread upon a successful connection. The server then has to print out how many times a file has been downloaded after its downloaded.
The thread when a file is downloaded calls a method in the server to increment the download count. However because its seperate threads when multiple clients connect it doesnt increment the updated number that another client might have set.
Output from my IDE to show what i mean:
Waiting for connection request...
Creating a new thread
Number of threads running: 1
Waiting for connection request...
File 1 has been downloaded 1 times.
Creating a new thread
Number of threads running: 2
Waiting for connection request...
File 1 has been downloaded 1 times.
Obviously File 1 should have been downloaded 2 times.
Any way to fix this?
Thanks,
David
Link to comment
https://www.neowin.net/forum/topic/706174-java-saving-integers-from-a-thread/Share on other sites
13 answers to this question
Recommended Posts