-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c095ac1
commit d19a835
Showing
13 changed files
with
106 additions
and
17 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
...oot-cloud-websocket/src/main/java/com/rotanava/boot/system/websocket/config/InitInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
package com.rotanava.boot.system.websocket.config; | ||
|
||
import com.rotanava.face.core.config.SpringStartListener; | ||
import com.rotanava.face.core.global.ThreadPoolUtil; | ||
import com.rotanava.boot.system.websocket.thread.ThreadPoolUtil; | ||
|
||
import com.rotanava.face.core.websocket.server.ServerBootStrap; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.ApplicationArguments; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Log4j2 | ||
public class InitInfo extends SpringStartListener { | ||
public class InitInfo implements ApplicationRunner { | ||
|
||
@Autowired | ||
ServerBootStrap serverBootStrap; | ||
|
||
|
||
@Override | ||
public void start(ConfigurableApplicationContext applicationContext) { | ||
public void run(ApplicationArguments args) throws Exception { | ||
ThreadPoolUtil.execute(() -> serverBootStrap.run()); | ||
log.info("项目启动成功"); | ||
log.info("websocket项目启动成功"); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...oud-websocket/src/main/java/com/rotanava/boot/system/websocket/thread/ThreadPoolUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.rotanava.boot.system.websocket.thread; | ||
|
||
|
||
|
||
import java.util.concurrent.*; | ||
|
||
public class ThreadPoolUtil { | ||
|
||
public static ThreadPoolExecutor threadPool; | ||
|
||
/** | ||
* 无返回值直接执行 | ||
* ThreadRun<?,?> 可以传递两个参数给新线程使用 | ||
* @param runnable | ||
*/ | ||
public static void execute(ThreadRun<?,?> runnable){ | ||
getThreadPool().execute(runnable); | ||
} | ||
|
||
/** | ||
* 无返回值直接执行 | ||
* ThreadRun<?,?> 可以传递两个参数给新线程使用 | ||
* @param runnable | ||
*/ | ||
public static void execute(Runnable runnable){ | ||
getThreadPool().execute(runnable); | ||
} | ||
|
||
|
||
/** | ||
* 多线程获取返回值 | ||
* @param callable | ||
*/ | ||
public static <T> Future<T> submit(Callable<T> callable){ | ||
return getThreadPool().submit(callable); | ||
} | ||
|
||
|
||
/** | ||
* dcs获取线程池 | ||
* @return 线程池对象 | ||
*/ | ||
public static ThreadPoolExecutor getThreadPool() { | ||
if (threadPool != null) { | ||
return threadPool; | ||
} else { | ||
synchronized (ThreadPoolUtil.class) { | ||
if (threadPool == null) { | ||
threadPool = new ThreadPoolExecutor(8, 16, 60, TimeUnit.SECONDS, | ||
new LinkedBlockingQueue<>(32), new ThreadPoolExecutor.CallerRunsPolicy()); | ||
} | ||
return threadPool; | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ot-cloud-websocket/src/main/java/com/rotanava/boot/system/websocket/thread/ThreadRun.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.rotanava.boot.system.websocket.thread; | ||
|
||
public abstract class ThreadRun<T,E> implements Runnable{ | ||
private T param; | ||
private E param2; | ||
public ThreadRun(T param,E param2){ | ||
this.param=param; | ||
this.param2=param2; | ||
} | ||
@Override | ||
public void run() { | ||
try { | ||
execute(param,param2); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public abstract void execute(T param, E param2) throws Exception; | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ spring: | |
application: | ||
name: rotanava-boot-module-system-websocket | ||
profiles: | ||
active: dev | ||
active: test |
Binary file removed
BIN
-25.8 KB
...ud-module/rotanava-boot-cloud-websocket/src/main/resources/lib/comoon-websocket-1.0.7.jar
Binary file not shown.