refactor: 重构包内容

This commit is contained in:
Bunny 2025-01-21 21:54:05 +08:00
parent 92408bf244
commit 853b64a173
42 changed files with 71 additions and 47 deletions

View File

@ -0,0 +1,26 @@
package thead.pool;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPoolNewCached {
public static void main(String[] args) {
ExecutorService executorService = Executors.newCachedThreadPool();
// 提交多个任务
for (int i = 0; i < 10; i++) {
final int taskId = i;
executorService.submit(() -> {
System.out.println("Task " + taskId + " executed by: " + Thread.currentThread().getName());
try {
Thread.sleep(2000); // 模拟任务执行
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
// 关闭线程池
executorService.shutdown();
}
}

View File

@ -1,4 +1,4 @@
package thread_safe.safe0;
package thead.safe.safe0;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package thread_safe.safe0;
package thead.safe.safe0;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package thread_safe.safe1;
package thead.safe.safe1;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package thread_safe.safe2;
package thead.safe.safe2;
import java.util.concurrent.atomic.AtomicInteger;

View File

@ -1,4 +1,4 @@
package thread_safe.safe3;
package thead.safe.safe3;
public class Run {
public static void main(String[] args) {

View File

@ -1,4 +1,4 @@
package thread_safe.safe4;
package thead.safe.safe4;
public class SynchronizedMethodLocakObject {

View File

@ -1,4 +1,4 @@
package thread_safe.safe4;
package thead.safe.safe4;
public class SynchronizedMethodLocakObject2 {

View File

@ -1,4 +1,4 @@
package thread_safe.safe5;
package thead.safe.safe5;
// 在多线程编程中synchronized 关键字可以确保一个线程在执行某个方法时其他线程无法同时访问被同步的方法从而避免多个线程同时修改共享数据的问题
// 脏读Dirty Read指的是一个线程读取到另一个线程还未提交的修改数据这种数据在另一个线程最终提交或者回滚后可能会发生变化因此是不可靠的

View File

@ -1,4 +1,4 @@
package thread_safe.safe6;
package thead.safe.safe6;
/**
* sychronized 锁重入指的是一个线程在获得一个锁之后可以再次进入该锁即再次获取锁而不会发生死锁

View File

@ -1,4 +1,4 @@
package thread_safe.safe7;
package thead.safe.safe7;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package thread_safe.safe8;
package thead.safe.safe8;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package thread_safe.safe9;
package thead.safe.safe9;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ConcurrentSkipListSet;

View File

@ -1,4 +1,4 @@
package thead;
package thead.start;
import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package thead.thread_0;
package thead.start.thread_0;
public class DeadlockExample {
private static final Object lock1 = new Object();

View File

@ -1,4 +1,4 @@
package thead.thread_1;
package thead.start.thread_1;
public class MyThread extends Thread {
@Override

View File

@ -1,4 +1,4 @@
package thead.thread_1;
package thead.start.thread_1;
public class ThreadApplication1 {
public static void main(String[] args) {

View File

@ -1,4 +1,4 @@
package thead.thread_1;
package thead.start.thread_1;
import java.util.concurrent.TimeUnit;

View File

@ -1,4 +1,4 @@
package thead.thread_2;
package thead.start.thread_2;
public class MyRunnable implements Runnable {
/**

View File

@ -1,4 +1,4 @@
package thead.thread_2;
package thead.start.thread_2;
public class RunnableApplication {
public static void main(String[] args) {

View File

@ -1,4 +1,4 @@
package thead.thread_3;
package thead.start.thread_3;
public class Application {
public static void main(String[] args) {
@ -12,7 +12,7 @@ public class Application {
MyThread myThread8 = new MyThread(8);
MyThread myThread9 = new MyThread(9);
MyThread myThread10 = new MyThread(10);
myThread1.start();
myThread2.start();
myThread3.start();

View File

@ -1,4 +1,4 @@
package thead.thread_3;
package thead.start.thread_3;
public class MyThread extends Thread {

View File

@ -1,4 +1,4 @@
package thead.thread_4;
package thead.start.thread_4;
public class Application {
// 有线程安全的操作

View File

@ -1,4 +1,4 @@
package thead.thread_4;
package thead.start.thread_4;
public class Application2 {
public static void main(String[] args) {

View File

@ -1,4 +1,4 @@
package thead.thread_4;
package thead.start.thread_4;
public class MyThread extends Thread {

View File

@ -1,4 +1,4 @@
package thead.thread_5;
package thead.start.thread_5;
public class Application3 {
public static void main(String[] args) throws InterruptedException {

View File

@ -1,4 +1,4 @@
package thead.thread_5;
package thead.start.thread_5;
public class MyThread extends Thread {
@Override

View File

@ -1,4 +1,4 @@
package thead.thread_5;
package thead.start.thread_5;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package thead.thread_6;
package thead.start.thread_6;
import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

View File

@ -1,4 +1,4 @@
package thead.thread_6;
package thead.start.thread_6;
public class Run {
public static void main(String[] args) {

View File

@ -1,4 +1,4 @@
package thead.thread_6;
package thead.start.thread_6;
import lombok.SneakyThrows;

View File

@ -1,4 +1,4 @@
package thead.thread_6;
package thead.start.thread_6;
import lombok.SneakyThrows;

View File

@ -1,4 +1,4 @@
package thead.thread_7;
package thead.start.thread_7;
public class Run {
public static void main(String[] args) {

View File

@ -1,4 +1,4 @@
package thead.thread_7;
package thead.start.thread_7;
public class Service {
public synchronized static void methodB() {

View File

@ -1,4 +1,4 @@
package thead.thread_7;
package thead.start.thread_7;
public class ThreadA extends Thread {

View File

@ -1,4 +1,4 @@
package thead.thread_7;
package thead.start.thread_7;
public class ThreadB extends Thread {

View File

@ -1,4 +1,4 @@
package thead.thread_8;
package thead.start.thread_8;
public class MyThread extends Thread {
@Override

View File

@ -1,4 +1,4 @@
package thead.thread_8;
package thead.start.thread_8;
public class Run {
public static void main(String[] args) {

View File

@ -1,4 +1,4 @@
package thead.thread_8;
package thead.start.thread_8;
public class Run3 {
public static void main(String[] args) {

View File

@ -1,6 +1,7 @@
package thead.thread_9;
package thead.start.thread_9;
import thead.Box;
import thead.start.Box;
public class MyThread extends Thread {
/**

View File

@ -1,6 +1,7 @@
package thead.thread_9;
package thead.start.thread_9;
import thead.Box;
import thead.start.Box;
public class Test1 {
public static void main(String[] args) {

View File

@ -1,4 +0,0 @@
package threadPool;
public class ThreadPoolNewCached {
}