Servlet, wait and an asynchronous call.
Hi Guys,
Need some guidance. Here is what I am trying to design.
I have a swt client that connects to a servlet via apache's httpclient and sends a request. Upon receiving the request, the servlet publishes it to a different component asynchronously. The component after a bit of processing (usually 1-2 seconds) will start to send responses intermittently for a given number of seconds. The servlet will receive and forward them to the client.
The challenge for me it to make the servlet wait till the component has started to publish the responses and written multiple responses back to the client.
Here is what i have come up with: The servlet gets the request from the client, calls a class that has a thread to publish it to the component. The thread will wait till the component sends back a response. Once the response is received (by a different thread), the waiting thread will be notified and the control will go back to the servlet. The servlet will flush the response and wait for the subsequent responses.
Does it sound feasible or have I neglected some key issues? Any ideas, links, code snippets would be very helpful.
Cheers,
Vic
Message was edited by:
vics_31
Message was edited by:
vics_31
make your worker thread put the responces in a blocking queue and make the servlet read from the queue. So when the queue is empty it has to wait.
But normally we do not create threads in servlets its a bit unusuall design.
Similar Messages
-
The program tries to find the first socket connection. Theirs a wait and the notify call in the inner class seams to have to effect. Attach is the code to try out
import java.io.*;
import java.util.*;
import java.net.*;
import java.nio.channels.*;
* SocketSearch class to scan for an open socket from an array of sockets passed. <br>
* Inner class DetectSocketConnection tries to open the socket and assign hostname
* a value if successful. <br>
* The SocketSearch thread class is waiting to find the hostname or active DetectSocketConnection
* threads to be zero - i.e No hosts found
public class SocketSearch extends Thread {
private Object syncObject = new Object();
private String hostname = null;
private ThreadGroup threadGroup = new ThreadGroup("SOCKETS_CONNECT");
private ArrayList sockets = null;
* Inner class DetectSocketConnection to find an open socket. <br>
* It will assign the hostname a value if successful
private class DetectSocketConnection extends Thread {
private SocketChannel sc = null;
private String host = null;
private int port = -1;
public DetectSocketConnection(String host, int port) {
super(threadGroup, host);
this.host = host;
this.port = port;
System.out.println("DetectSocketConnection::syncObject = " + syncObject);
public void run() {
System.out.println("Scanning " + host + " at port number " + port);
synchronized(syncObject) {
try {
InetSocketAddress isa = new InetSocketAddress(InetAddress.getByName(host), port);
// Connect
sc = SocketChannel.open();
sc.connect(isa);
System.out.println("Found hostname: " + host + "!!!!!!!!!!!!!!!!!!!");
hostname = host;
catch (IOException e) {
System.err.println("DetectSocketConnection: " + e.toString());
finally {
// Make sure we close the channel (and hence the socket)
close();
System.out.println("DetectSocketSonnectio: notify()...");
syncObject.notify();
public void close() {
try {
if (sc != null) sc.close();
catch (IOException e) {
public SocketSearch() {
sockets = new ArrayList();
* Add socket to the sockets ArrayList to prepare to start the Socket Search
* @param host Socket hostname
* @param port Socket port number
public void addSocket(String host, int port) {
DetectSocketConnection detectSocket = new DetectSocketConnection(host, port);
sockets.add(detectSocket);
* SocketSearch start method to fire up the sockets threads to search for
public void start() {
super.start();
if (sockets != null) {
DetectSocketConnection[] arrSockets = (DetectSocketConnection[]) sockets.toArray(new DetectSocketConnection[0]);
for (int i = 0 ; i < arrSockets.length ; i++) {
arrSockets.start();
* Main code to do the socket search
public void run() {
try {
boolean loop = (sockets.size() > 0);
while (loop) {
synchronized(syncObject) {
System.out.println("SocketSearch.wait() => syncObject = " + syncObject);
syncObject.wait();
System.out.println("SocketSearch.wait() => syncObject = " + syncObject + ", finished...");
if (hostname != null) {
// use the hostname
// you could interrupt the threads now - its your choice
loop = false;
else {
System.out.println("Invalid hostname...");
ThreadGroup currentGroup = Thread.currentThread().getThreadGroup();
int numThreads = currentGroup.activeCount();
Thread[] listOfThreads = new Thread[numThreads];
currentGroup.enumerate(listOfThreads);
int activeThreads = 0;
for (int i = 0 ; i < numThreads ; i++) {
if (listOfThreads[i] instanceof DetectSocketConnection) {
activeThreads++;
System.out.println("activeThreads: " + activeThreads);
if (activeThreads == 0) {
// host name is NULL and active threads are finished
throw new UnknownHostException("Host not found.");
if (hostname != null) {
System.out.println("Found hostname: " + hostname);
// Do something here, use callback to maybe dispose ProgressDialog etc...
catch (UnknownHostException e) {
// Do something here, use callback to maybe dispose ProgressDialog etc...
System.err.println(e.toString());
catch (InterruptedException e) {
// Do something here, use callback to maybe dispose ProgressDialog etc...
System.err.println(e.toString());
* Test to find a socket from an array of test socket hosts
public static void main(String args[]) {
String[] yahooPOP3PossibleSettings = new String[] {
"yahoo.com",
"mail.yahoo.com",
"pop.yahoo.com",
"pop.mail.yahoo.com",
"pop3.yahoo.com"
int PORT_NUMBER = 110;
SocketSearch socketSearch = new SocketSearch();
for (int i = 0 ; i < yahooPOP3PossibleSettings.length ; i++) {
socketSearch.addSocket(yahooPOP3PossibleSettings[i], PORT_NUMBER);
socketSearch.start();Forget it. The Inner class was doing a wait and so was the main thread.
Not meant to put a wait in the main thread... -
Wait() and notifyall() problem in servlet.
Can anyone help me with this.....
I am creating an application which has one gateway inside which
handles for logger, dbmodule etc are made and passed to biz logic.
This biz logic using logger obj made in gateway, does the logging.
Now i hv to do serial implementation of logging i.e I have
a static member which is of type Vector, which will hold
a list of messages and associated parameters. The write() method will
create a formatted message with all values inserted, all prefixes and
suffixes added, etc. Then it will append the message to the Vector of
messages. And there will be a separate thread, which will be started
the
first time the first Logger instance is created. This thread will keep
picking up messages from this Vector in FIFO order and writing them
out.Mind you, I don't mean i need to use a single shared Logger
instance.
Separate Logger instances must be used to hold separate values for
sessionID, username, etc. Only the internal logging I/O stream handle
should be shared.
For this what i hv created logger class as follows:
logger {
SyslogAppender SA;
logger() {
new SA;
ThreadGroup TG = new ThreadGroup("string");
Logging target = new Logging();
Thread DT = new Thread(TG, target, "daemon");
DT.setDaemon(true);
DT.start();
class write {
write() {
//initialisation;
void writetovector() {
addtovector
notifyall;
class logging implements runnable {
public void run() {
while(vector is not empty){
log
synchronised(this){
wait();
Now in the servlet, in init(), logger is called with this constructor
and therefore there is only one instance of syslog appender to log in
syslog.
In service i just call the function writetovector through a method in
logger.
However when i run the implemented version of this, logging does not
take place.
I feel my implementation of wait and notifyall is not correct. Or is
there any other problem?
thanx in advanceThere are many problems with your code. It looks like you retyped it, and it now contains many syntax errors. Two problems I can see, though, are that you do not call notifyAll from synchronized code, and your call to wait is not in a loop.
-
Wait and notify in servlets?
i am having a servlet , which is implementing wait and notify of java.lang.Object.
when serving it for single request , its waiting and working fine...
but for multiple requests its not serving properly. works one by one means the second request is waiting for finishing the first request just like SingleThreadModel (after finishing the first request only second request entering inside servlet)
please help me to solve this?
or is there any other way to call wait method without synchronized block??Shynihan wrote:
or is there any other way to call wait method without synchronized block??No, and that's partly because if wait or notify is the only thing in the synchronized block then you probably aren't using them right. The problem is blocking the server thread. Servlet engines use a thread pool to execute transactions, when a new transaction comes in a thread is taken from the pool to run it, and there's usually a limited number of threads in the pool. If there's no threads left then the transaction will wait for another to finish.
If your servlets freeze up, then that's a thread gone from the pool.
And remeber the unlocking transaction may never arive. The client could go down at any time, leaving the server thread permanently hung.
You need to move this waiting to the client side. If the transaction cannot proceed then return a "come back later" response immediately. The client can then retry after a decent interval. -
Wait on Asynchronous Call - why so long?
LV 2013, Win7
I have a window which comes and goes, during program operation.
This window has 72 subPanels, each containing a reentrant copy of the same VI for a "block". I insert the VI in the subpanel, and then run the VI with a CALL and FORGET call.
When the user closes the window, all the block VIs terminate, and the window closes. I don't care if the closing behind the scenes still goes on after the window disappears.
But when the user QUITs the program, with this window up, I need to make sure that all the block VIs have terminated before I shut down other things (close files, etc).
To that end, I changed the CALL and FORGET to a CALL and COLLECT operation, and installed a WAIT ON ASYNCHRONOUS CALL for each instance at the end of the big window code. This is after the blocks have been commanded to die (via an event).
I see from the debugging file (a portion is pictured) that it takes over 1000 mSec to wait for all the instances to die.
The thing is, if I change that "0" to "1000", then what I would expect is that the actual waiting time would drop to < 100 mSec.
My thinking is that during that timed wait, the blocks would be dying anyway, so it would take less time to actually wait on them.
But when I do that, nothing really changes. The listed time is still over 1000 mSec.
If I limit the number of blocks to 12, the time is 97 mSec, for 24 it is 185, for 36 it is 576, and so on - it's proportional to the number of blocks.
So, what is really happening? If it's just waiting on things to die, why doesn't the timed wait affect the numbers?
I originally (when I used CALL and FORGET) kept track of how many were opened and how many were closed and waited until that became zero, but this is a cleaner way of doing it, at least in theory.
Am I missing something?
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com
Blog for (mostly LabVIEW) programmers: Tips And Tricks
Solved!
Go to Solution.Have you checked how long the first loop of the For loop takes, versus all of the others?
So I tried that, several times - the pattern is the same as shown here. The first few lines are from the blocks themselves, it's the last thing they do.
Looks like there's ONE case where there's a bigger delay than expected, All told, this takes about 600 mSec.
Maybe the debugging process affects that (* waves to Mr. Heisenberg * )
The 300-400 mSec is back to where I first saw this delay. Apparently the unreleased refs clog up the system enough to drive it up to 1000 (or 2000 mSec as I saw in one case).
Still, I don't understand why a timed delay ahead of the WAITS doesn't affect the WAIT time.
But I guess that's not important. It must be actually doing more work than simply asking "is it dead yet?"
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com
Blog for (mostly LabVIEW) programmers: Tips And Tricks -
What is a gateway proxy?? what are synchronous and asynchronous calls?
bapis are rfc enabled. but are there any other rfc's available in sap? what is a gateway proxy?? what are synchronous and asynchronous calls?
Hello:
Lets st art at the beginning.
There are NO documented viruses that affect a Mac running OS X - none (there are instances of Malware).
Gateway GEO-IP/BOTNET Alert
This is a Youtube video that explains what you have (I assume you installed it somehow) on your computer:
http://www.youtube.com/watch?v=JwRi2me2hSk
For openers, I would uninstall any A/V software you have put on your system. It is certainly possible that that junk has put some other stuff on your computer.
I'm also afraid my computer might have been hacked?
Highly unlikely.
Barry -
Does JAM help making synchronous and asynchronous calls to CICS
I want to integrate mainframes and j2ee application. Does JAM provide synchronous and as well as asynchronous call to CICS from j2ee and vice-versa
I want to integrate mainframes and j2ee application. Does JAM provide synchronous and as well as asynchronous call to CICS from j2ee and vice-versa
-
We are currently using Jolt 1.2 connected to a Tuxedo 6.5 system on Solaris.
We are porting a Windows thick application to browser. We call a Tuxedo
service
with the old system that takes around 10 minutes to complete. We obviously
call this
asynchronously. When we call this same service using Jolt it "times-out".
Which makes
sense since Jolt 1.2 seems to only allow synchronous ( aka
Request-Response ) calls.
I have looked at the documentation for Jolt 1.2, 1.2.1, the Jolt with Tuxedo
7.1 and Tuxedo 8 and
I cannot find an ability to make a Asynchronous call. However, I did find
it in the API documentation
for the Jolt that comes with Weblogic Enterprise 5.1 and above? Are these
APIs available without
Weblogic Enterprise? Is there a special Jolt add-on package?
Thanks for the info,
Carl J. Collin
Walgreen Co.
[email protected]Thank you very much. That is exactly what our engineers came up with
to get around this. The problem is that we have no ability to be notified
when this async service is finished. In our old application we would lock
the window manually (windows api) and run a loop doing getReplies until
the async returned a buffer. With a browser model, it probably isn't
possible
without having an applet or something. It just rubs me raw that the API I
need
for Jolt isn't supplied when you BUY JOLT, but only if you buy the
SUPER-EXPENSIVE
Weblogic Enterprise. Why have a Jolt product to begin with if you do not
supply the whole
functionality needed to merge Java and Tuxedo, which is the supposedly the
product's goal?
Carl J. Collin
Walgreen Co.
[email protected]
"Manoj SASIDHARAN" <[email protected]> wrote in message
news:[email protected]...
>
Hello Carl J. Collin,
I can suggest a workaround to make things happen.
From the browser call a Tuxedo service (synchronously) using Jolt whichinternally
does the following:
SVC(TPSVINFO...)
SvcName="Name of Service Currently called from Browser..";
ret=tpacall(SvcName,... TPNOREPLY);
tpreturn(...);
HTH
regards
MS
"Carl J. Collin" <[email protected]> wrote:
We are currently using Jolt 1.2 connected to a Tuxedo 6.5 system on
Solaris.
We are porting a Windows thick application to browser. We call a Tuxedo
service
with the old system that takes around 10 minutes to complete. Weobviously
call this
asynchronously. When we call this same service using Jolt it"times-out".
Which makes
sense since Jolt 1.2 seems to only allow synchronous ( aka
Request-Response ) calls.
I have looked at the documentation for Jolt 1.2, 1.2.1, the Jolt with
Tuxedo
7.1 and Tuxedo 8 and
I cannot find an ability to make a Asynchronous call. However, I did
find
it in the API documentation
for the Jolt that comes with Weblogic Enterprise 5.1 and above? Are
these
APIs available without
Weblogic Enterprise? Is there a special Jolt add-on package?
Thanks for the info,
Carl J. Collin
Walgreen Co.
[email protected] -
Phone keeps ringing on the caller's end - Is This a Call Waiting and Flash Button Problem?
I had FIos phone service installed 2 weeks ago. I am having a sporadic but regularly occurring issue with incoming calls that I think might be related to the Call Waiting and flash button so I am looking for some input. Before describing the issue here are a couple of things to know:
- I have my Verizon voice mail service turned off on my account.
- I have the call waiting function set to off.
- On my phone handset the Talk and Flash operation is the same button.
Now here is my issue. Often but not 100% of the time people are telling me that the phone just rings and rings on their end. After receiving many complaints since my Fios install that the phone rings and my phone answering machine does not pick up the call I have been calling my home phone number with my cell phone and I have determined the following:
1. My home answering machine will pick up the call, however on my cell phone which is the calling end the phone is still just ringing.
2. Sometimes I will press the talk button but there will be dead air but on my cell phone which is the calling end it will still be ringing.. But if I press the Talk/Flash button a couple of times the call completes.
Since my Talk and Flash button are the same I started to wonder if that is a factor so I repeated scenarios above and found that after pressing the Talk button a couple of times then the call is answered and the phone stops ringing on the caller's end.
I know that with Call Waiting the caller's end will just keep ringing unless the called end switches over with the Flash button. So my question is even though I have the Call Waiting function turned off could the combination Talk/Flash button be the reason why the call just rings on the caller's end even though I have Call Waiting turned off? And f this is the cause then why is it happening and does it mean that I have to buy a new phone that has separate Talk and Flash buttons?
I hope the above description of my problem makes sense and can be answered. Thank youWithout buying a new phone you can test this. Unplug the phone that has the combination button. If its a cordless phone base station with multiple handsets, make sure you unplug those as well. Then use a regular phone plugged in to do test calls (if you dont have one you could maybe borrow one for a couple minutes from a friend, family, or neighbor).
Anthony_VZ
**If someones post has helped you, please acknowledge their assistance by clicking the red thumbs up button to give them Kudos. If you are the original poster and any response gave you your answer, please mark the post that had the answer as the solution**
Notice: Content posted by Verizon employees is meant to be informational and does not supersede or change the Verizon Forums User Guidelines or Terms or Service, or your Customer Agreement Terms and Conditions or plan -
Updated to IOS 7.1 and now my "Call Waiting" does not work, nor will the "Call Waiting" indicator stay on..... Any help?
Settings > General > Reset > Reset Network Settings
-
Problem disconnecting a participant in call waiting and conference calls.
I have a Z10 running 10.3.2 on Verizon. I have not found a way to hang up on one caller in a call waiting or conference call without disconnecting all calls. The only option the screen offers is the end call button. I can switch between callers and merge calls just fine but if I try to end one of those calls, it will disconnect all participants and end the call completely. Does anybody have a solution to this?
Ok. So I completely forgot about this until the flag I put on the problem came up.
So it is working now and as you suggested I called Telusand they "pushed" the SIM and refreshed the switch "in the back". Have no clue what either of those actions entails the critical item being that it now works.
Thanks -
Call waiting and forwarding suddenly disabled !
Dears
I have noticed that call waiting and forward calls some times disabled automatically, so everytime I have again to go to call setting and do reactivation for call waiting and forward calls for both SIMS
Kindly need your support why this issue keep repeating!!!Hi ziyadalsayed,
Welcome to the community! Since you're new please be sure that you have checked out our Discussion guidelines.
The Call settings such as forwarding are maintained by your network carrier, you may be able to change this section however your network carrier can change it back to defaults.
I suggest that you contact them first to clarify if they have issues using this function on your account at the moment.
I apologize for the inconvenience this may cause,
- Official Sony Xperia Support Staff
If you're new to our forums make sure that you have read our Discussion guidelines.
If you want to get in touch with the local support team for your country please visit our contact page. -
Unexpected loop behaviour with asynchronous call
I am having trouble with loop behaviour when using an asynchronous call.
I am building an application to record simultaneously temperature (NI USB-TC01 thermocouple), displacement (DC voltage, read from an Agilent 34401a) and resistivity (using a Keithley 2400 sourcemeter).
I am using a voltage sweep function on the Keithley 2400 to alternate current direction in a sample and measure the voltage drop - this is a common technique for eliminating thermal emf from resistance measurements. But what you need to know is that I set the number of current cycles I want and then wait for the instrument to measure and return the meausurements - up to 50 samples, which takes nearly 30 seconds. With the other two measurements, I have to programmatically call a measurement vi for each sample I want.
I have set up my application to asynchronously program the resistivity measurement and then wait for the response, and I want to in parallel measure temperature and position until the resistivity is done. I then want to record the mean and standard deviation for each signal. I used an event structure to interrupt the temperature and position measurements when done.
The problem I am running into is that after the first resistivity measurement is completed and I go to do the second one, the loop that measures temperature and displacement only runs twice, so I only get two samples, regardless of how many resistivity samples I want to collect. For example, if I want 50 resistivity samples at a time, the first iteration will measure rougly 40 samples of temperature and displacement, but any subsequent iterations will only measure twice.
I know this is probably overwhelming to understand the operation, but can anyone help? I have attached my code ('Delatometer') as well as a test vi I built that uses the same structure but has no interactions with instruments ('asynchronousCall').
The
Attachments:
Delatometer.zip 221 KB
asynchronousCall.zip 29 KBI forgot to mention...the test vi that I uploaded executes as expected, so I am thinking that maybe its an issue with the instrument calls? I also found that if I run the Delatometer program in 'highligh execution mode' it runs properly, and it is my understanding that in 'highlight execution mode' there is no multi-threading.
-
Asynchronous Call By Reference Examples
The asynchronous Call By Reference feature was added to LabVIEW 2011 which introduced the Start Asynchronous Call node and the Wait On Asynchronous Call node. However, an oversight lead to the examples for this feature only being installed with the win32 version of LabVIEW 2011.
I attached the examples for those running a non-win32 LabVIEW 2011. These examples should reside in <examples>\viserver\AsynchronousCallByReference.
Attachments:
AsyncCallByRefExamples.zip 99 KBHi jcase,
Thank you for bringing this issue to our attention. I have created a Corrective Action Request to notify R&D of the issue. Sincerely,
Julianne K
Systems Engineer, Embedded Systems
Certified LabVIEW Architect, Certified LabVIEW Embedded Systems Developer
National Instruments -
Asynchronous Call - collect OR forget?
Hi all,
I want to optimize one of my LabView procedures. Let's say that I've got 2 VIs that return the same values, but use differend data sources. I'd like to launch both of them and simply collect the result from the faster one.
I figured I could do this by running both VIs asynchronously and polling a global variable, but I was hoping that there is a better solution.
If I "Wait on asynchronous call" for both VI, I'll wait for the slowest one to finish. Is there a way to check if VI has finished its job without running into "wait on asynchronous call"?
Thanks in advance!
Tomasz
Solved!
Go to Solution.In this case, I would probably go with the notifier. You could possibly also go with a User Event.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Maybe you are looking for
-
Hi Gurus, While raising a P.O for a subcontractor i have maintianed overdelivery tolerance of 5% in the Material Master and info record. Now i have created a P.O for 10 Kgs and send to the sub contractor for processing , value of the P.O is Rs. 2
-
Without installing extra software how can I get finder to read and write to
FTP accounts?
-
I have a new Mac Book Pro 13" & an iPad for my Amazon and eBay business. I have been a PC user. The problem relates to both. On my eBay Manager Sold page, the display of the page is wider than my screen. I use Safari and all other webpages are fine
-
How do you activate an iphone4??
Hello Everyone, im hoping you can help me. I recently ungraded my phone from an iphon4 to an iphone 5c, I sold my old iphone 4 to a friend and in order for them to activate it they needed me to enter my Apple ID and password. So i DID. However it wil
-
what does it mean that my laptop charger is flashing amber and green fast and my laptop will not turn on or simply do anything but make a continuous noise in the hardrive?