Reputation: 1234
ENVIRONMENT
We use apache tomcat to comunicate a visual layer (actionscript - flex) to the business layer (java). This comunication is used for lots of requests, the visual ask for data in the DB, and lots of operations.
THE PROBLEM
The problem is that we are interacting with a camera that only supports one session simultaneosly, and as far as i know apache tomcat create lots of threads, which are trying to comunicate with the camera at the same time.
Maybe you are thinking that its a bad implementation that we made, but the problem is that there is a functionality (the live view -showing images directly like recording video-) which makes imposible to release the camera after asking for the instant picture.
BEING MORE ESPECIFIC
In all the others method which interact to the cam, there is no problem beacause we make the follow steps:
1-oppen session with the cam
2-make whatever with the cam
3-release the cam
This steps works fine with almost all the methods (like taking pictures or downloading theme to the pc), but for the live view, we cant oppen a session and closing it every time (beacuase it makes an important delay, and the camera needs tobe ready), so we have to leave the session oppened while the live view, the procedure is something like this:
First live view pic
1-oppen session with cam
2-download live view pic
Second and next pics
1-download live view pic
Final live view pic
1-download live view pic
2-release the cam
In the first time when we are working with a simple thread all works fine, but if after other calls, new threads were created, and two treads try to do live view (one oppened session and the other wants to interact with the cam), the tomcat get freezed...
CONCLUSION
The problem we have is that Tomcat creates lots of thread when java comunicate with the visual layer, but if the thread want to access to the camera and the session was oppened for another, tomcat get freezed...
THE QUESTION
There is a way to make apache tomcat works with an especific thread for a call to a java method???
NOTE
We debug and try all the methods in easy eclipse working with one thread and everything works fine...
Upvotes: 0
Views: 304
Reputation: 1234
The solution i found is using the code in other question, now i have only one thread alive, maybe this solution can generate some delay problems...
Upvotes: 0
Reputation: 691645
The problem is not with the threads Tomcat uses. The problam is with the absence of exclusive access to the camera. You should use a Semaphore (with a unique permit), acquire a permit when opening the session with the camera, and release the permit when releasing the session with the camera.
This way, all the threads will be blocked until they can acquire the permit. Semaphore can handle timeouts or can try to acquire the permit, so a thread wanitng to access the camera can still answer with an error message if some other thread uses it.
Upvotes: 1