What's the best practice to synchronize file access under servlet environment

S

stone0660

Hi every body

I am new to multi thread programming.
Now I have to control multi request for multi file accessing(offcourse
read and write) under servlet container.

Anyone can give me some advice? some programming model?

thanks in advance
 
I

Ingo R. Homann

Hi stone,

Hi every body

I am new to multi thread programming.
Now I have to control multi request for multi file accessing(offcourse
read and write) under servlet container.

Anyone can give me some advice? some programming model?

thanks in advance

Do you need file synchronization only withing one JVM or over different
JVMs?

If the latter one, this will be complicated, it the first one, this
should be relatively easy: Canonicalize the filename and use it as key
in a Map that gives you an Object to synchronize on.

Perhaps you must watch out on symbolical liks...?

Ciao,
Ingo
 
A

Andrea Desole

Ingo said:
Do you need file synchronization only withing one JVM or over different
JVMs?

If the latter one, this will be complicated, it the first one, this
should be relatively easy: Canonicalize the filename and use it as key
in a Map that gives you an Object to synchronize on.

I never had this issue, but in case of more processes accessing the same
file you might try the following: from a File object build your file
input/output stream; from that you can get the FileChannel for your
file, and on that you can call lock() to get exclusive access.
 
A

Andrew Thompson

(e-mail address removed) wrote:

(single JVM)
..should be relatively easy: Canonicalize the filename and use it as key
in a Map that gives you an Object to synchronize on.

Perhaps you must watch out on symbolical liks...?

File.getCanonicalPath()

Should account for the symbolic links. From the docs..
"This typically involves removing .., resolving symbolic links
(on UNIX platforms), and converting ..".
 
J

jan V

I am new to multi thread programming.
Now I have to control multi request for multi file accessing(offcourse
read and write) under servlet container.

Anyone can give me some advice? some programming model?

My advice, given that you are new to multithreading, is to not continue with
your project until you have studied the subject for a while. Your question
really should be "What are the best books on multithreading in Java?"

If your managers are competent, they will allow you to allocate several days
purely to the above further education.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top