File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed
lts-admin/src/main/java/com/lts/admin/support
lts-monitor/src/main/java/com/lts/monitor Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -47,12 +47,12 @@ public void contextInitialized(ServletContextEvent servletContextEvent) {
4747 if (StringUtils .isEmpty (ltsMonitorCfgPath )) {
4848 ltsMonitorCfgPath = this .getClass ().getResource ("/" ).getPath ();
4949 }
50- MonitorAgentStartup .main ( new String []{ ltsMonitorCfgPath } );
50+ MonitorAgentStartup .start ( ltsMonitorCfgPath );
5151 }
5252 }
5353
5454 @ Override
5555 public void contextDestroyed (ServletContextEvent servletContextEvent ) {
56-
56+ MonitorAgentStartup . stop ();
5757 }
5858}
Original file line number Diff line number Diff line change 33import com .lts .core .commons .utils .StringUtils ;
44
55import java .util .Map ;
6+ import java .util .concurrent .atomic .AtomicBoolean ;
67
78/**
89 * @author Robert HG ([email protected] ) on 3/5/16. 910 */
1011public class MonitorAgentStartup {
1112
13+ private final static MonitorAgent agent = new MonitorAgent ();
14+ private static final AtomicBoolean started = new AtomicBoolean (false );
15+
1216 public static void main (String [] args ) {
1317 String cfgPath = args [0 ];
1418 start (cfgPath );
1519 }
1620
17- private static void start (String cfgPath ) {
21+ public static void start (String cfgPath ) {
22+
23+ if (!started .compareAndSet (false , true )) {
24+ return ;
25+ }
1826
1927 try {
2028 MonitorCfg cfg = MonitorCfgLoader .load (cfgPath );
2129
22- final MonitorAgent agent = new MonitorAgent ();
23-
2430 agent .setRegistryAddress (cfg .getRegistryAddress ());
2531 agent .setClusterName (cfg .getClusterName ());
2632 if (StringUtils .isNotEmpty (cfg .getBindIp ())) {
@@ -46,4 +52,10 @@ public void run() {
4652 }
4753 }
4854
55+ public static void stop () {
56+ if (started .compareAndSet (true , false )) {
57+ agent .stop ();
58+ }
59+ }
60+
4961}
You can’t perform that action at this time.
0 commit comments