[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
Highlighted
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"
Highlighted
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!

What’s New for Talend Spring ’19

Join us live for a sneak peek!

Sign up now

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch