how to make a function in separate thread

i need to make a function that is running in a separate threadThank's in advance
[95 byte] By [bakr_awada] at [2007-11-26 13:29:21]
# 1

You can wrap with Runnable,

Thread thread = new Thread(new Runnable() {

public void run() {

// Call the function here.

}

);

thread.start();

AjaySingh516a at 2007-7-7 20:33:34 > top of Java-index,Core,Core APIs...
# 2
http://java.sun.com/docs/books/tutorial/essential/concurrency/
jverda at 2007-7-7 20:33:34 > top of Java-index,Core,Core APIs...
# 3

Thank's

but in my program i have a main class which is a server it runs forever.

from the main class when i call a function it runs in a separate thread and returns the result to the callee and the main function continue it's work

class server

{

//this function when called must be in separate thread

public int function(int x)

{

//there could be wait here or sleep

return x*2;

}

public static void main(String[] args)

{

// Run RMI server

}

}

i hope u understand me!!!

Thank's

bakr_awada at 2007-7-7 20:33:34 > top of Java-index,Core,Core APIs...
# 4

All you need can be found in the referenced tutorial, Jeff linked to in reply #3. It won't be quicker to ask concurrency basics step by step in this forums. If you have doubt on the concept of concurrency in general, do yourself a favour and get a good book (some also mentioned in the tutorial).

stefan.schulza at 2007-7-7 20:33:34 > top of Java-index,Core,Core APIs...
# 5

> Thank's

>

> but in my program i have a main class which is a

> server it runs forever.

> from the main class when i call a function it runs in

> a separate thread and returns the result to the

> callee and the main function continue it's work

Previous answers apply.

jverda at 2007-7-7 20:33:34 > top of Java-index,Core,Core APIs...
# 6
See the FAQ for some references.
davidholmesa at 2007-7-7 20:33:35 > top of Java-index,Core,Core APIs...