This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / Re #15734: how to lock a file in Java?
I mean how java provide flock()?
-guest:function?;
2000-11-25
(#15756@0)
-
Sorry, this is the first I hear method "flock()". Is there such a function in Java? Would you please give me further information or just let me know what you want to do?
-ericwu(Eric Wu);
2000-11-25
(#15758@0)
-
他是说文件访问的互斥,即一个进程读写文件时
-guest:别的进程对该文件的访;
2000-11-25
(#15762@0)
-
被禁止
-guest:这应该很重要;
2000-11-25
(#15763@0)
-
OK, I guess(guess!) I understand you now. First, it depends on your OS. Sometimes your OS will do this work for you. Second, you may use key word "synchronized" to adjust a statement to let this statement(s) can beOK, I guess(guess!) I understand you now. First, it depends on your OS. Sometimes your OS will do this work(exclusively operate a file) for you. Second, you may use the key word "synchronized" to adjust statement(s) to let this statement(s) can be invoked by only one thread. So, a file can only be accessed by one user.
May be I will send you short sample codes.
-ericwu(Eric Wu);
2000-11-26
{369}
(#15811@0)
-
"synchronized" in Java programming can not completely solve the problem of file locking."synchronized" in Java programming can not completely solve the problem of file locking. Suppose 1. there are two PCs on network where they can access a file on a file server on the same newwork. Or 2. There are two tasks running on the same PC and attempt to access a file simutaneously. How can "synchronized" do ...
-old(HH);
2000-11-26
{325}
(#15833@0)
-
'HOW TO....?' is a typical english mistake we chinese speakers..tend to make. The correct way is "how do you...?". Sorry for
interrupting. I am taking an English course now, so I am very
interested in finding our common mistakes
-wjiang(wjiang);
2000-12-1
{171}
(#16742@0)
-
"How to" or "How do you"You can use "How to" as the title of a document. For example, "How to Lock a File in Java". But, if you want to ask a question, use: "How do you lock a file in Java?"
-guest:Kursat;
2000-12-1
{172}
(#16746@0)
-
you are absolutely correct!we can still use 'how to' as a title or a sentence component such as 'do you know HOW TO ...?
I pointed the HOW TO problem because I am used to say in the wrong way and many people is still makeing the same mistake very frequently. Especially in a interview, pay attention to 'how to'
-wjiang(wjiang);
2000-12-1
{290}
(#16752@0)
-
Jabber's understanding.
-jabber(jabber);
2000-11-27
{4108}
(#16021@0)
-
Jabber, thank you. You are an expert.
-ericwu(Eric Wu);
2000-11-27
(#16054@0)
-
NOT TRUE
-jabber(jabber);
2000-11-29
(#16377@0)
-
how to implement flock() in BBS forum like rolia?
how to maintain the message numberFile file = new File("xxx.txt");
synchronized(file) { // operate on the file }
"synchronized" is a function?
if it is a functin what class does it belong to?
-guest:servlet?;
2000-11-28
{170}
(#16236@0)
-
message numberusually message number is stored in a file
suppose it is 1000
servlet A read num=1000
servlet B read num=1000
servlet A increase num=1001
servlet B increase num=1001
servelt A write 1001
servelt B write 1001 !
the num should be 1002!
-guest:servlet;
2000-11-28
{243}
(#16240@0)
-
who can answer this question?I am just a undergraduation CS
-guest:student;
2000-11-29
(#16395@0)
-
sorry!It should be
-guest:"undergraduate ";
2000-11-29
(#16396@0)
-
Dear Servlet, I cannot understand your postings.One thing I can explain to you. synchronized is a key word in Java. It is not a function.
-jabber(jabber);
2000-11-29
{89}
(#16400@0)
-
HOW to block other servlets(may be intants of same servlet) from reading and writing to a file when one servlet is accessing the same file.(mutual exclusive of file access)
-guest:servlet;
2000-11-29
(#16414@0)
-
About "Servlet"'s message number ...
-old(HH);
2000-11-29
{1279}
(#16425@0)
-
300 intsances of 50 servlets write to the same file ....
-jabber(jabber);
2000-12-1
{700}
(#16716@0)
-
I have found the solution myself on java.sun.com. Use a new file as a semaphore. Through it have some drawback,but it is platform independence. thank you all
-guest:servlet;
2000-12-1
(#16719@0)
-
Dear Servlet, can you give us the link for the solution at Sun's site? Thanks a million....
-jabber(jabber);
2000-12-1
(#16733@0)
-
Jabber, I read it, too.In a synchronized block, create a new file---lock it;
To unlock it, just delete this file in aother synchronized block.
-marcow(UserMarco);
2000-12-1
{120}
(#16765@0)
-
I think we can have two strategies,1) within samWithin same VM use synchronized method. 2) Between two VM use new_file or other semaphore
-guest:servlet;
2000-12-2
(#16865@0)
-
So simple? so easy? I am stunned.
-jabber(jabber);
2000-12-2
(#16866@0)
-
I get confused with something. The file is really locked inside JVM? I think I must misunderstand something important. Please let me know more details, thank you very much!
-old(HH);
2000-12-3
(#16911@0)