Have tried to resolve this issue but it is proving difficult.
I have two threads, one is a producer, and the other a consumer. All in separate classes. The two threads run independently. The producer is pooling about 8-12 folders for inputs. It then translates all the files concurrently and place in a shared folder called 'readyToLoad'. Once the producer thread finishes, the consumer threads now go into the 'readyToLoad' folder and start processing the translated documents.
Now to the issue, while the consumer is processing the translated documents, it wouldn't allow the producer to put in more translated files into the 'readyToLoad' folder.
My question is, how do I prevent the consumer from locking the 'readyToLoad' folder? How can I manage this situation?
Apologies for the long text but I feel it will help understand where I'm having issues. Thanks for your help all.
UPDATE : added the consumer code (the one that performs loading and locks the file while loading is going on)
public class LoadManager {
protected static final Logger logger = KCLogger.getLogger();
ArrayList<Loader> threads = new ArrayList<Loader>();
KCBLConfig config;
private static final ExecutorService service = Executors.newFixedThreadPool(10);
public LoadManager(KCBLConfig config) {
this.config = config;
}
public void start() throws Exception {
logger.log(Level.INFO, "Starting loading threads.");
try {
TreeMap<String, ConnectionHandler> connectionHandlers = config.getConnectionHandlers();
Iterator i = connectionHandlers.keySet().iterator();
while (i.hasNext()) {
ConnectionHandler connectionHandler = connectionHandlers.get((String) i.next());
for (LoadFolder loadFolder : connectionHandler.getKcXMLFolders()) {
Loader loader = new Loader(loadFolder.getId(), loadFolder, config.getConnectionHandlers());
Thread loaderThread = new Thread(loader);
loaderThread.start();
//service.submit(loader);
// service.shutdown();
//service.awaitTermination(1, TimeUnit.MILLISECONDS);
threads.add(loader);
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, "There was an error starting the loaders. Stopping all loader threads.", e);
this.stop();
throw e;
}
logger.log(Level.INFO, "All loader threads created. There are " + threads.size() + " loader threads");
}