Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

sleeping in servlet deffers writing to res output stream.

Thread view: 
null7 - 23 Jan 2006 09:46 GMT
Hallo

Below is my service method. Sleep causes that data are not written to `res'
stream immediatelly, but after some time, usually as the `while' loop
is finished and hence service method finishes.
My question is, how to make it be written immediatelly ?

Greetings

my service method:

 public void service( HttpServletRequest req, HttpServletResponse res )
   throws ServletException, IOException {

   res.setStatus( 200 ) ;
   res.setContentType( "text/plain" ) ;
   PrintStream out = new PrintStream( res.getOutputStream() );

   for ( int i = 1; i < 20; i++ ) {
     out.println( "my text" );
     try {
    int timeMillis = 5000;
    System.out.println( "Sleeping for a " + timeMillis/1000 + " secs..." );
    out.flush(); // this and the line below does not help.
    res.flushBuffer();
    Thread.sleep( timeMillis ); // wait 5 seconds
     } catch ( InterruptedException ie ) { }
   }
 }
Raymond DeCampo - 23 Jan 2006 14:08 GMT
> Hallo
>
[quoted text clipped - 25 lines]
>     }
>   }

I do not know the answer to your direct question, but I suspect we can
help you if you tell us what you are *really* trying to accomplish.  Why
do you want to sleep during a servlet call?

HTH,
Ray

Signature

This signature intentionally left blank.

null7 - 23 Jan 2006 17:33 GMT
>> Hallo
>> Below is my service method. Sleep causes that data are not written
[quoted text clipped - 27 lines]
> HTH,
> Ray

The servlet is going to have an open connection to its caller, for a very long time (a few days).
Its task will be to read some files on local filesystem every 15 secs and in case there
is anything to be passed to the caller, it will do that. Otherwise it will sleep for another 15 secs.
That is why I need servlet to sleep.

Greetings
Raymond DeCampo - 29 Jan 2006 14:38 GMT
>>>Hallo
>>>Below is my service method. Sleep causes that data are not written
[quoted text clipped - 32 lines]
> is anything to be passed to the caller, it will do that. Otherwise it will sleep for another 15 secs.
> That is why I need servlet to sleep.

This doesn't sound like something that fits the servlet architecture
very well.  You might want to go with a traditional client/server
application.  Or, if you want J2EE, use JMS (i.e. have your clients
subscribe to a JMS topic and have a timed app post a message to the
topic whenever there are updates to the files).

HTH,
Ray

Signature

This signature intentionally left blank.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.