Forums Register Login

Calling a thread from shell script

+Pie Number of slices to send: Send
Hi,

I have got a shell script which calls a java program(BuildPage.java). I have created a thread and is starting from BuildPage.java. My intention was not to build pages concurrently as this script is calling from many places. So i have created a Thread (CreatePage.java) and started it from BuildPage.java.
In this, i'm creating a lock file in the synchronised method and removing it after build is over.
From webapplication, i'm calling the script to build the pages from a servlet. While building, the application hangs. I'm not much familiar with Threads.
Please help me to get rid of this problem. Also please suggest any different way of implementation for this.

Thanks in advance..




// ============================================


// ============================================

// ============================================



[NK: Please UseCodeTags]
+Pie Number of slices to send: Send
In the following code:



The variable isExecute is a local variable. Since, no one can change (and changes) this value your run() method will never return unless you explicitly break from within the while() loop.
+Pie Number of slices to send: Send
I see several issues here:

1)

You assign isExecute = getLockFile(); and then execute the while loop. The isExecute variable will never be changed, so the loop will be executed either forever (if getLockFile() returned true) or never (if it returned false). I think that you wanted to check the isExecuted condition each time (correct me if I'm wrong), so the following would be more correct:


2)
In the getLockFile() method you call wait() if the lock file exists. The wait() method is called on this object (the CreatePublicPages object). The object should be notified by another thread, but the only place it is notified is the removeLockFile() method of the same object, which is executed sequentially by the same object. So the bug is that:
- a Runnable CreatePublicPages (let's call it cpp) is created and started in a new thread
- cpp.run() is executed
- cpp.getLockFile() is entered from cpp.run()
- if a lock file exists, cpp.wait() is called, causing cpp's thread to stop the execution and to wait for a notification
- no-one can notify cpp, because the only place cpp is notified is in cpp.removeLockFile(), but cpp can never get there because it is waiting for notification - deadlock

The solution would be to use a common object for all CreatePublicPages threads and to synchronize on it and call the wait/notifyAll methods of tat object. Or, even better, to use some kind of a high-level mutex, like Semaphore or Lock. For further info on synchronization, have a look at the Sun's concurrency tutorial
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1813 times.
Similar Threads
Monitor FIFO (mkfifo) file - start / stop not working
Deleting a lock file not working.
How to open a file using Java
Synchronizing between two threads, one implements Runnable the other extends Thread
Locking issues in Max's book sample project - Denny's DVD store
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:00:54.