楼主什么意思?
public class ThoughtServer implements Runnable {
//Registered name of the remote object as a constant
public final static String THOUGHT_RO_NAME = "TheThoughtRO"; private String temp = null;//保留args[0]参数值
private ThoughtROImpl theThoughtROImpl = null; public ThoughtServer( String temp ) {
this.temp = temp;
} public static void main(String[] args) {
Thread thread1 = new Thread( new ThoughtServer( args[0] ) );
thread1.start();
} public void run() {
go();
} private void go() {
//Create a remote object instance
//Note: you must catch the RemoteException thrown
//by the ThoughtROImpl constructor
try {
theThoughtROImpl = new ThoughtROImpl(); //Bind the remote object to the registry
//Note: here we are catching any exceptions thrown
//by the bindRO() method
bindRO();
}
catch(Exception e) {
e.printStackTrace();
}
} private void bindRO() throws Exception
{
//Register remote object with naming registry
Naming.rebind(THOUGHT_RO_NAME, theThoughtROImpl);
System.out.println("The ThoughtROImpl has been registered");
}
}
public class ThoughtServer implements Runnable {
//Registered name of the remote object as a constant
public final static String THOUGHT_RO_NAME = "TheThoughtRO"; private String temp = null;//保留args[0]参数值
private ThoughtROImpl theThoughtROImpl = null; public ThoughtServer( String temp ) {
this.temp = temp;
} public static void main(String[] args) {
Thread thread1 = new Thread( new ThoughtServer( args[0] ) );
thread1.start();
} public void run() {
go();
} private void go() {
//Create a remote object instance
//Note: you must catch the RemoteException thrown
//by the ThoughtROImpl constructor
try {
theThoughtROImpl = new ThoughtROImpl(); //Bind the remote object to the registry
//Note: here we are catching any exceptions thrown
//by the bindRO() method
bindRO();
}
catch(Exception e) {
e.printStackTrace();
}
} private void bindRO() throws Exception
{
//Register remote object with naming registry
Naming.rebind(THOUGHT_RO_NAME, theThoughtROImpl);
System.out.println("The ThoughtROImpl has been registered");
}
}
当有其它的人调用接口的时候,
用start 就是多线程了.
import java.rmi.Naming;public class ThoughtServer extends Thread{
//Registered name of the remote object as a constant
public final static String THOUGHT_RO_NAME = "TheThoughtRO"; public ThoughtServer() {
} public void run(String[] args) {
//Create a remote object instance
//Note: you must catch the RemoteException thrown
//by the ThoughtROImpl constructor
try {
theThoughtROImpl = new ThoughtROImpl(); //Bind the remote object to the registry
//Note: here we are catching any exceptions thrown
//by the bindRO() method
bindRO();
}
catch(Exception e) {
e.printStackTrace();
}
} private void bindRO() throws Exception
{
//Register remote object with naming registry
Naming.rebind(THOUGHT_RO_NAME, theThoughtROImpl);
System.out.println("The ThoughtROImpl has been registered");
} private ThoughtROImpl theThoughtROImpl; public static void main(String[] args) {
//Create main object reference
ThoughtServer theThoughtServerApp1 = new ThoughtServer();
ThoughtServer theThoughtServerApp2 = new ThoughtServer();
theThoughtServerApp1.run(args);
theThoughtServerApp2.run(args);
}
}
ThoughtClient-----就是interface
ThoughtRO:
ThoughtRMImpl------就是連接database
ThoughtServer------server
我應該從那改和應該什樣做.....我只會做一個單程的server, 大寫可不可以幫幫幫忙.....
ThoughtServer class:
mport java.rmi.Naming;public class ThoughtServer {
//Registered name of the remote object as a constant
public final static String THOUGHT_RO_NAME = "TheThoughtRO"; public ThoughtServer() {
} public static void main(String[] args) {
//Create main object reference
ThoughtServer theThoughtServerApp = new ThoughtServer(); theThoughtServerApp.go(args);
} private void go(String[] args) {
//Create a remote object instance
//Note: you must catch the RemoteException thrown
//by the ThoughtROImpl constructor
try {
theThoughtROImpl = new ThoughtROImpl(); //Bind the remote object to the registry
//Note: here we are catching any exceptions thrown
//by the bindRO() method
bindRO();
}
catch(Exception e) {
e.printStackTrace();
}
} private void bindRO() throws Exception
{
//Register remote object with naming registry
Naming.rebind(THOUGHT_RO_NAME, theThoughtROImpl);
System.out.println("The ThoughtROImpl has been registered");
} private ThoughtROImpl theThoughtROImpl;
}