When using Dubbo to start the server, you need to keep the backend running. The following figure shows that the input stream is used to block the server on the Internet:
System. In. Read (); // to ensure that the service is always on, use the congestion of the input stream to simulate it;
Find a new method and use the Lock Object class to block it so that it will not be closed
Explanation:Synchronized (XXX. Class)
Xxx. Class is a static attribute of XXX class and an object. The xxx. Class lock is used to lock the entire class. That is to say, no matter how many XXX class objects are created, these objects share the same lock tag.
Use:
<Span style = "color: # ff0000;"> synchronized (provider. Class) </span> {// wait for the thread after the server starts. The service has been running while (true) {try {provider. Class. Wait ();} catch (interruptedexception e) {system. Out. println (e );}}}
Provider is the class name, which adds a lock to this class object. When other requests come, they will wait until the end of the previous process. The complete content is as follows:
Public class provider {public static void main (string [] ARGs) throws exception {classpathxmlapplicationcontext context = new classpathxmlapplicationcontext (New String [] {"applicationcontext. XML "}); context. start (); // system. in. read (); // to ensure that the service is always on, simulate <span style = "color: # ff0000;"> synchronized (provider. class) </span> {// wait for the thread after the server starts. The service has been running while (true) {try {provider. Class. Wait ();} catch (interruptedexception e) {system. Out. println (e );}}}}}