[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
Two Stars

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
Two Stars

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!

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch