[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: VFS locking

mstruk do-not-reply at jboss.com
Mon Jun 30 15:21:02 EDT 2008


anonymous wrote : so there is a magic flag, after all?

There is a flag, but it's not magic :)

I've spent a lot of time on this lately.

A general rule that works for file: urls (but not for jar:file: urls) is the following:


  |       URLConnection conn = fileUrl.openConnection();
  |       InputStream in = conn.getInputStream();
  |       long lastModified;
  |       try
  |       {
  |          lastModified = conn.getLastModified();
  |          System.out.println("lastModified, "+lastModified);
  |       }
  |       finally
  |       {
  |          in.close();
  |       }
  | 

It's getting and closing the InputStream that does the trick.

For jar:file: urls I could only achieve file lock release by triggering finalizers - which means it's pretty useless for anything but tests maybe:


  |       URLConnection conn = jarFileUrl.openConnection();
  |       conn.setUseCaches(false);
  | 
  |       long lastModified = conn.getLastModified();
  | 
  |       conn = null;
  |       jarFileUrl = null;
  |       System.gc();
  |       Thread.sleep(500);
  |       System.gc();
  | 

In this case I'd say the problem is more with JDK implementation than Windows :)

- marko


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4161584#4161584

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4161584



More information about the jboss-dev-forums mailing list