forked from lets-blade/blade
-
Notifications
You must be signed in to change notification settings - Fork 0
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
c6880e7
commit 556d869
Showing
18 changed files
with
190 additions
and
130 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
blade-core/src/main/java/com/blade/kit/AbortPolicyWithReport.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.blade.kit; | ||
|
||
import java.util.concurrent.RejectedExecutionException; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
public class AbortPolicyWithReport extends ThreadPoolExecutor.AbortPolicy { | ||
|
||
private final String threadName; | ||
|
||
public AbortPolicyWithReport(String threadName) { | ||
this.threadName = threadName; | ||
} | ||
|
||
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) { | ||
String msg = String.format("Blade[" | ||
+ " Thread Name: %s, Pool Size: %d (active: %d, core: %d, max: %d, largest: %d), Task: %d (completed: %d)," | ||
+ " Executor status:(isShutdown:%s, isTerminated:%s, isTerminating:%s)]", | ||
threadName, e.getPoolSize(), e.getActiveCount(), e.getCorePoolSize(), e.getMaximumPoolSize(), e.getLargestPoolSize(), | ||
e.getTaskCount(), e.getCompletedTaskCount(), e.isShutdown(), e.isTerminated(), e.isTerminating()); | ||
System.out.println(msg); | ||
throw new RejectedExecutionException(msg); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
blade-core/src/main/java/com/blade/kit/BladeThreadPool.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,20 @@ | ||
package com.blade.kit; | ||
|
||
import java.util.concurrent.*; | ||
|
||
public class BladeThreadPool { | ||
|
||
public static Executor getExecutor(int threads, int queues) { | ||
return getThreadPoolExecutor(threads, queues); | ||
} | ||
|
||
public static ThreadPoolExecutor getThreadPoolExecutor(int threads, int queues) { | ||
String name = "blade-pool"; | ||
return new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS, | ||
queues == 0 ? new SynchronousQueue<Runnable>() | ||
: (queues < 0 ? new LinkedBlockingQueue<Runnable>() | ||
: new LinkedBlockingQueue<Runnable>(queues)), | ||
new NamedThreadFactory(name, true), new AbortPolicyWithReport(name)); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
blade-core/src/main/java/com/blade/kit/NamedThreadFactory.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,43 @@ | ||
package com.blade.kit; | ||
|
||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class NamedThreadFactory implements ThreadFactory { | ||
|
||
private static final AtomicInteger threadNumber = new AtomicInteger(1); | ||
|
||
private final AtomicInteger mThreadNum = new AtomicInteger(1); | ||
|
||
private final String prefix; | ||
|
||
private final boolean daemoThread; | ||
|
||
private final ThreadGroup threadGroup; | ||
|
||
public NamedThreadFactory() { | ||
this("blade-threadpool-" + threadNumber.getAndIncrement(), false); | ||
} | ||
|
||
public NamedThreadFactory(String prefix) { | ||
this(prefix, false); | ||
} | ||
|
||
public NamedThreadFactory(String prefix, boolean daemo) { | ||
this.prefix = prefix + "-thread-"; | ||
daemoThread = daemo; | ||
SecurityManager s = System.getSecurityManager(); | ||
threadGroup = (s == null) ? Thread.currentThread().getThreadGroup() : s.getThreadGroup(); | ||
} | ||
|
||
public Thread newThread(Runnable runnable) { | ||
String name = prefix + mThreadNum.getAndIncrement(); | ||
Thread ret = new Thread(threadGroup, runnable, name, 0); | ||
ret.setDaemon(daemoThread); | ||
return ret; | ||
} | ||
|
||
public ThreadGroup getThreadGroup() { | ||
return threadGroup; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.blade.mvc.route; | ||
package com.blade.mvc.handler; | ||
|
||
import com.blade.mvc.http.Request; | ||
import com.blade.mvc.http.Response; | ||
|
@@ -24,8 +24,9 @@ | |
* @author <a href="mailto:[email protected]" target="_blank">biezhi</a> | ||
* @since 1.5 | ||
*/ | ||
@FunctionalInterface | ||
public interface RouteHandler { | ||
|
||
public void handle(Request request, Response response); | ||
void handle(Request request, Response response); | ||
|
||
} |
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
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
Oops, something went wrong.