Network online game development experience (server side) (7)

xiaoxiao2021-03-06  38

Bromon original, respect copyright seven, start and exit

In order for the system to have satisfactory performance, we should reuse objects as much as possible, and reduce the creation of new objects. For example, the message mentioned above, our operation is to provide a static class. Initialization when the system is started, keep the connection with the JMS server, when sending a message, do not query JNDI and generate QueueConnectionFactory, this can be improved System response speed. On the issue of the database connection pool, we also use the same operation, initialize N connectivity when starting. But if you do not do anything when you turn off the process, it will cause JMS to throw Socket anomalies, although there is no big impact, but always seem to be professional, and the connection in the pool is not released, or may result in problems. It is best to allow the system like a console program such as JBoss, and Ctrl C will be able to perform the operation, release the resource and then exit. We can implement it by adding a hook to process / threads, and Windows programmers should be very familiar with this.

Hook should be a thread method, as follows:

Package Org.bromon.games.al; Public Class Hook Extends Thread

{

Public void Run ()

{

/ / Release the database connection, destroy the connection pool

// Close the connection with JMS

}

}

Add in the main thread:

Runtime.Getruntime (). Addshutdownhook (new hook ());

Then the process / thread performs hook's RUN method and cleanup resources when exiting.

转载请注明原文地址:https://www.9cbs.com/read-68881.html

New Post(0)