xuxueli 6 anni fa
parent
commit
3957ef2ff7

+ 1 - 1
doc/XXL-JOB官方文档.md Vedi File

@@ -347,7 +347,7 @@ XXL-JOB是一个轻量级分布式任务调度平台,其核心设计目标是
347 347
     <property name="appName" value="${xxl.job.executor.appname}" />
348 348
     <!-- 执行器IP[选填],为空则自动获取 -->
349 349
     <property name="ip" value="${xxl.job.executor.ip}" />
350
-    <!-- 执行器端口号[选填],为空则自动获取 -->
350
+    <!-- 执行器端口号[选填],小于等于0则自动获取 -->
351 351
     <property name="port" value="${xxl.job.executor.port}" />
352 352
     <!-- 访问令牌[选填],非空则进行匹配校验 -->
353 353
     <property name="accessToken" value="${xxl.job.accessToken}" />

+ 1 - 1
xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java Vedi File

@@ -129,7 +129,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
129 129
     private NetComServerFactory serverFactory = new NetComServerFactory();
130 130
     private void initExecutorServer(int port, String ip, String appName, String accessToken) throws Exception {
131 131
         // valid param
132
-        port = port>0?port: NetUtil.findAvailablePort(9999,ip);
132
+        port = port>0?port: NetUtil.findAvailablePort(9999);
133 133
 
134 134
         // start server
135 135
         NetComServerFactory.putService(ExecutorBiz.class, new ExecutorBizImpl());   // rpc-service, base on jetty

+ 8 - 27
xxl-job-core/src/main/java/com/xxl/job/core/util/NetUtil.java Vedi File

@@ -2,10 +2,8 @@ package com.xxl.job.core.util;
2 2
 
3 3
 import org.slf4j.Logger;
4 4
 import org.slf4j.LoggerFactory;
5
-import org.springframework.util.StringUtils;
6 5
 
7 6
 import java.io.IOException;
8
-import java.net.InetSocketAddress;
9 7
 import java.net.ServerSocket;
10 8
 
11 9
 /**
@@ -17,24 +15,23 @@ public class NetUtil {
17 15
     private static Logger logger = LoggerFactory.getLogger(NetUtil.class);
18 16
 
19 17
     /**
20
-     * find avaliable port by ip
18
+     * find avaliable port
21 19
      *
22 20
      * @param defaultPort
23
-     * @param ip
24 21
      * @return
25 22
      */
26
-    public static int findAvailablePort(int defaultPort,String ip) {
23
+    public static int findAvailablePort(int defaultPort) {
27 24
         int portTmp = defaultPort;
28 25
         while (portTmp < 65535) {
29
-            if (!isPortUsed(portTmp,ip)) {
26
+            if (!isPortUsed(portTmp)) {
30 27
                 return portTmp;
31 28
             } else {
32 29
                 portTmp++;
33 30
             }
34 31
         }
35
-        portTmp = --defaultPort;
32
+        portTmp = defaultPort--;
36 33
         while (portTmp > 0) {
37
-            if (!isPortUsed(portTmp,ip)) {
34
+            if (!isPortUsed(portTmp)) {
38 35
                 return portTmp;
39 36
             } else {
40 37
                 portTmp--;
@@ -44,33 +41,17 @@ public class NetUtil {
44 41
     }
45 42
 
46 43
     /**
47
-     * find avaliable port
48
-     *
49
-     * @param defaultPort
50
-     * @return
51
-     */
52
-    public static int findAvailablePort(int defaultPort) {
53
-        return findAvailablePort(defaultPort,null);
54
-    }
55
-
56
-
57
-    /**
58 44
      * check port used
59 45
      *
60 46
      * @param port
61
-     * @param ip 为空则为 InetAddress.anyLocalAddress()
62 47
      * @return
63 48
      */
64
-    public static boolean isPortUsed(int port,String ip) {
49
+    public static boolean isPortUsed(int port) {
65 50
         boolean used = false;
66 51
         ServerSocket serverSocket = null;
67 52
         try {
68
-            if(StringUtils.isEmpty(ip)){
69
-                serverSocket = new ServerSocket(port);
70
-            }else {
71
-                serverSocket = new ServerSocket();
72
-                serverSocket.bind(new InetSocketAddress(ip,port));
73
-            }
53
+            serverSocket = new ServerSocket(port);
54
+            used = false;
74 55
         } catch (IOException e) {
75 56
             logger.debug(">>>>>>>>>>> xxl-job, port[{}] is in use.", port);
76 57
             used = true;

+ 1 - 1
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/applicationcontext-xxl-job.xml Vedi File

@@ -29,7 +29,7 @@
29 29
 		<property name="appName" value="${xxl.job.executor.appname}" />
30 30
 		<!-- 执行器IP[选填],为空则自动获取 -->
31 31
 		<property name="ip" value="${xxl.job.executor.ip}" />
32
-		<!-- 执行器端口号[选填],为<0则自动获取 -->
32
+		<!-- 执行器端口号[选填],小于等于0则自动获取 -->
33 33
 		<property name="port" value="${xxl.job.executor.port}" />
34 34
 		<!-- 访问令牌[选填],非空则进行匹配校验 -->
35 35
 		<property name="accessToken" value="${xxl.job.accessToken}" />