[resolved] How to creating a unique file name for temporary files

One Star

[resolved] How to creating a unique file name for temporary files

I would like to know if someone knows how to create a filename in a directory that is guaranteed to be unique.
I have several different jobs that use tHashOutput components extensively. In order to handle large data sets, I would like to use temporary files instead of tHash components to preserve memory. The problem I am concerned about is what will happen if two different jobs are running concurrently and both attempt to create a temporary file with the same name. I would like to be able to create a file on the fly without worrying about whether it will conflict with any other jobs.
Has anyone encountered this same issue?
Thanks.

Accepted Solutions
One Star

Re: [resolved] How to creating a unique file name for temporary files

I use the tCreateTemporaryFile component using System.getenv("TMP") as the Directory setting and then use the FILEPATH global variable to get the full path name.
The great thing is the file is then deleted automatically once the job finishes.

All Replies
One Star

Re: [resolved] How to creating a unique file name for temporary files

Use variable jobName and timestamp:
jobName+TalendDate.formatDate("yyyyMMddHHmmss",TalendDate.getCurrentDate())+".log"
One Star

Re: [resolved] How to creating a unique file name for temporary files

I use the tCreateTemporaryFile component using System.getenv("TMP") as the Directory setting and then use the FILEPATH global variable to get the full path name.
The great thing is the file is then deleted automatically once the job finishes.
One Star

Re: [resolved] How to creating a unique file name for temporary files

Thanks!