Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Enable Cross-platform File Locking with a Lock Server  : Page 4

A custom shared lock server can overcome file-locking differences between operating systems or Java implementations.


advertisement
Start the server, if it isn't already running, and specify a port on the command line:

$ java LockServer 5678 Listening on port 5678

Once your server is running, you can run the test program called Test.java. This program lets you specify the various locking parameters on the command line, like this:



$ java Test <host> <port> <filename> <position> <size> <shared> <try>

The test program will acquire the lock if it can, and then wait for you to press Return. When you press return, it will release the lock. Try running multiple copies of Test in different windows to see the locks interact.

Reconcile Cross-platform Differences
A lock server can make up for differences between operating systems or Java implementations. The file-locking specification allows each implementation to choose whether its locks are process-wide or system-wide, which can play havoc with a program that needs system-wide locks. In these situations, you can use a lock server to replace the functionality missing from the underlying implementation.

This approach is an excellent way to deal with cross-platform differences. Just write it yourself! If you run your program on a system that happens to have system-wide locking, the lock server will still work correctly.



Greg Travis is a freelance Java programmer and technology writer living in New York City. After spending three years in the world of high-end PC games, he joined EarthWeb, where he developed new technologies with the then new Java programming language. Since 1997, he has been a consultant in a variety of Web technologies. He can be reached at mito@panix.com.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date