What is the best way to generate a unique and short file name in Java

后端 未结 16 2401
不思量自难忘°
不思量自难忘° 2020-11-29 20:51

I don\'t necessarily want to use UUIDs since they are fairly long.

The file just needs to be unique within its directory.

One thought which comes to mind is

16条回答
  •  余生分开走
    2020-11-29 21:19

    Problem is synchronization. Separate out regions of conflict.

    Name the file as : (server-name)_(thread/process-name)_(millisecond/timestamp).(extension)
    example : aws1_t1_1447402821007.png

提交回复
热议问题