0

We have developed a resource adapter which will do the following two things

  1. Extract an archive file at a given location.
  2. Delete a given directory and its contents.

Both extraction and deletion are synchronous today.

While extracting the file we create a directory (originalName_tmp). After the extraction is successful, we rename it to originalName. Similarly while deleting, we rename it to originalName_tmp. Once we rename it, we delete the corresponding entry from the database. If it is successful we delete the renamed directory.

Today the extraction and deletion usecases each take more than 30 seconds. We don't mind the time taken to extract the archive file. But the deletion should happen quickly.

So we decided to create a new thread and do the deletion operation in that thread.

What is the best way to achieve this? I heard there will be a worker thread and we can grab and instance of it and submit a job/task to it. How can do this?

Thanks all in advance.

Krishna Chaitanya
  • 2,533
  • 4
  • 40
  • 74
  • 1
    Have you read through the concurrency lesson in the Java tutorial? It gives a lot of information about how to create and use threads. I suggest you read that and then come back here if there's anything you don't understand. http://docs.oracle.com/javase/tutorial/essential/concurrency/ – sprinter Jan 06 '15 at 05:18
  • @sprinter I read the docs and understood `Executor` is what I am looking for, with a fixed thread pool. – Krishna Chaitanya Jan 06 '15 at 10:05
  • Yes that sounds right to me. They are pretty powerful. Good luck. – sprinter Jan 06 '15 at 10:50

0 Answers0