I am trying to write a servlet using Apache Commons FileUpload. I am just wondering how to organize multiple file uploads if two users would use the same upload servlet?
Asked
Active
Viewed 258 times
1
-
1To learn more about servlets and threading, I suggest to read [this answer](http://stackoverflow.com/questions/3106452/java-servlet-instantiation-and-session-variables/3106909#3106909). – BalusC Mar 17 '11 at 18:52
1 Answers
2
No problem with that - just don't use instance variables of the servlet. Use only local variables.

Bozho
- 588,226
- 146
- 1,060
- 1,140
-
2@user592704 - if you don't have instance variables of the servlet you won't have multithreading problems. – Bozho Mar 17 '11 at 18:50
-
but the method I am going to use with the doPost is very long because it reads and writes client file... So the synch way may stuck all next requests for long time :( What should be done in that case? – user592704 Mar 17 '11 at 19:24
-
-
You mean I have to put all the code to doPut method only and that will help? – user592704 Mar 17 '11 at 20:31
-
No I don't use synchronized doX methods but I tried invoke the synchronized method (upload method) with doPost method... Correct me please – user592704 Mar 17 '11 at 20:34
-
@user592704 don't use any synchronized methods, and don't use any instance variables. – Bozho Mar 17 '11 at 20:46
-
What you mean saying "don't use any instance variables"? You mean I cannot do things like File file=new File("") ? – user592704 Mar 17 '11 at 21:35
-
@user592704 this is local variable. instance variables are those defined at class level. – Bozho Mar 17 '11 at 21:38
-
Oh, I used to know it as a "field" :) OK, so you mean all the read/write will be just for each one session so no need to use synchronized then? – user592704 Mar 18 '11 at 01:47