Hi Bala,
See this code :-
import java.io.*;
import java.util.*;
public class ThreadTest {
public static void main(String args[]) throws FileNotFoundException
{
T t = new T();
t.start(); // this is not printing any values.why?
t.say(); // this works well...
}
}
class T extends Thread {
PrintWriter out;
public T() throws FileNotFoundException {
out = new PrintWriter(System.out);
}
public T(PrintWriter pwt) throws IOException{
this.out = pwt;
}
public void say() {
out.println("Working Well----from say()");
out.flush();
}
public void run() {
out.println("Working Well----from Thread");
out.flush();
}
}
I have modified your code a bit and tried to run it. Now this is what I have
found
if you don't flush the output after out.println() it does not appear. I
don't know how, in your case, data appeared for t.say();
try out.flush() if it works for you
Regards,
Daljit
=======================
It's never too late to begin
=======================
----- Original Message -----
From: Balamurugan.K, AMB Chennai <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 02, 2000 3:27 PM
Subject: Problem with the thread in the servlet
> Hi,
> see this code:
>
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
>
> public class ThreadTest extends HttpServlet {
> public void doGet(HttpServletRequest
req,HttpServletResponse
> res) throws IOException {
> T t = new T(res.getWriter());
> t.start(); // this is not printing any
values.why?
> t.say(); // this works well...
> }
> }
> class T extends Thread {
> PrintWriter out;
> public T(PrintWriter pwt) throws IOException{
> this.out = pwt;
> }
> public say() {
> out.println("Working Well----from say()");
> }
> public void run() {
> out.println("Working Well----from Thread");
> }
> }
>
> This program prints only for say() method, whereas it is not
> printing anything when i call this thru thread.
> can any one tell why .......?
>
>
> Regards,
> Balamurugan K,
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html