N
null7
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 ) { }
}
}
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 ) { }
}
}