tags:

views:

153

answers:

4

hi, i need answer for the question i have mentioned in the title.

+2  A: 

No, there is no way to extends from two classes in Java. If you want you can have your servlet class implement java.lang.Runnable interface. But if you explained us better what yi are actually trying to achieve we could help you better.

flybywire
+4  A: 

No. A Java class can only have one superclass.

Why would you want to though? You can extend HttpServlet and implement Runnable. You can then call new Thread(this) - although frankly I'd recommend separating out the servlet and the runnable aspect anyway.

Jon Skeet
@Jon Skeet: I have been in stackoverflow for a while and I see ur answers in most of the questions and those are really too good.
Techmaddy
That's why he's #1!
Marc Novakowski
A: 

Hi,

i have servlet and thread. In thread i am trying to run the batch file and wait for 15 minutes.

i have something in servlet to load the image in html page after waiting for 15 miutes

A: 

Look at javax.servlet.ServletContextListener for implementing threads in a web application. It is generally a bad idea to start threads in servlets - the listener makes sure you only have one thread and that it is started when the application starts. It also allows you to elegantly stop the thread when the application is stopped (i.e. when the servlet context is destoyed). You can use a Thread Monitor pattern to send a notification to the thread to start/pause/stop processing etc. methods in this pattern would be Thread.notify() and Thread.wait(). You can create the thread in the contextInitialized() method