TiDBPingCAP 2011-06-11
private static String getUniqueId()
{
intcurrent;
synchronized(DefaultFileItem.class)
{
current=counter++;
}
Stringid=Integer.toString(current);
if(current<100000000)
{
id=("00000000"+id).substring(id.length());
}
returnid;
}
privatestaticStringgetUniqueId()
{
intcurrent;
synchronized(DefaultFileItem.class)
{
current=counter++;
}
Stringid=Integer.toString(current);
if(current<100000000)
{
id=("00000000"+id).substring(id.length());
}
returnid;
}
1.不要用""+整数来拼接字符串。调用Integer.toString高效
2.公有数据加同步保护
protectedFilegetTempFile()
{
FiletempDir=this.repository;
if(tempDir==null)
{
tempDir=newFile(System.getProperty("java.io.tmpdir"));
}
Stringfilename="upload_"+getUniqueId()+".tmp";
Filef=newFile(tempDir,fileName);
f.deleteOnExit();
returnf;
}
注意删除f.deleteOnExit在jvm退出的时候删除文件