refactor: 重构代码

This commit is contained in:
Bunny 2025-01-21 21:39:23 +08:00
parent 44cb49b87a
commit 6058183f18
79 changed files with 96 additions and 89 deletions

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Encoding"> <component name="Encoding">
<file url="file://$PROJECT_DIR$/localTools/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/multithreading1/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/multithreading1/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/multithreading1/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/multithreading1/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/multithreading1/src/main/resources-filtered" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/multithreading1/src/main/resources-filtered" charset="UTF-8" />

View File

@ -7,6 +7,11 @@
<option value="$PROJECT_DIR$/pom.xml" /> <option value="$PROJECT_DIR$/pom.xml" />
</list> </list>
</option> </option>
<option name="ignoredFiles">
<set>
<option value="$PROJECT_DIR$/multithreading1/pom.xml" />
</set>
</option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />

View File

@ -7,10 +7,10 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>multithreading1</artifactId> <artifactId>localTools</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>multithreading1</name> <name>localTools</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<properties> <properties>

View File

@ -1,4 +1,4 @@
package thead.subtitle; package cn.bunny.starTrek;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@ -1,11 +1,11 @@
package thead.subtitle.video; package cn.bunny.video;
import cn.bunny.video.dao.Response;
import cn.bunny.video.dao.VideoEntity;
import cn.bunny.video.utils.HttpRequestUtils;
import cn.bunny.video.utils.SystemControlUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import thead.subtitle.video.dao.Response;
import thead.subtitle.video.dao.VideoEntity;
import thead.subtitle.video.utils.HttpRequestUtils;
import thead.subtitle.video.utils.SystemControlUtils;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;

View File

@ -1,12 +1,12 @@
package thead.subtitle.video; package cn.bunny.video;
import cn.bunny.video.dao.Response;
import cn.bunny.video.dao.VideoEntity;
import cn.bunny.video.utils.HttpRequestUtils;
import cn.bunny.video.utils.SystemControlUtils;
import io.micrometer.common.util.StringUtils; import io.micrometer.common.util.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import thead.subtitle.video.dao.Response;
import thead.subtitle.video.dao.VideoEntity;
import thead.subtitle.video.utils.HttpRequestUtils;
import thead.subtitle.video.utils.SystemControlUtils;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;

View File

@ -1,4 +1,4 @@
package thead.subtitle.video.dao; package cn.bunny.video.dao;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package thead.subtitle.video.dao; package cn.bunny.video.dao;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package thead.subtitle.video.dao; package cn.bunny.video.dao;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package thead.subtitle.video.utils; package cn.bunny.video.utils;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference; import com.alibaba.fastjson2.TypeReference;

View File

@ -1,4 +1,4 @@
package thead.subtitle.video.utils; package cn.bunny.video.utils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package cn.bunny.atomic; package atomic;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.profile.StackProfiler; import org.openjdk.jmh.profile.StackProfiler;

View File

@ -1,4 +1,4 @@
package cn.bunny.atomic; package atomic;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.atomic; package atomic;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -8,7 +8,7 @@ public class AtomicExample04 {
// 此时为1 // 此时为1
latch.countDown(); latch.countDown();
System.out.println(latch.getCount()); System.out.println(latch.getCount());
// 此时为0 // 此时为0
latch.countDown(); latch.countDown();
System.out.println(latch.getCount()); System.out.println(latch.getCount());

View File

@ -1,4 +1,4 @@
package cn.bunny.atomic; package atomic;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;

View File

@ -1,4 +1,4 @@
package cn.bunny.atomic; package atomic;
import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.PriorityBlockingQueue;

View File

@ -1,4 +1,4 @@
package cn.bunny.atomic; package atomic;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;

View File

@ -1,4 +1,4 @@
package cn.bunny.atomic; package atomic;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.atomic; package atomic;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.atomic.reference; package atomic.reference;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;

View File

@ -1,4 +1,4 @@
package cn.bunny.atomic.reference; package atomic.reference;
import lombok.Getter; import lombok.Getter;

View File

@ -1,9 +1,9 @@
package feture.feture; package feture;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;
public class MyFutureTask { public class MyFutureTask01 {
public static void main(String[] args) { public static void main(String[] args) {
FutureTask<Integer> futureTask = new FutureTask<>(new Callable<>() { FutureTask<Integer> futureTask = new FutureTask<>(new Callable<>() {

View File

@ -1,9 +1,9 @@
package feture.feture_2; package feture;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;
public class MyFutureTask { public class MyFutureTask02 {
public static void main(String[] args) { public static void main(String[] args) {
FutureTask<Integer> futureTask = new FutureTask<>(new Callable<>() { FutureTask<Integer> futureTask = new FutureTask<>(new Callable<>() {

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole; import org.openjdk.jmh.infra.Blackhole;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.Runner;

View File

@ -1,4 +1,4 @@
package cn.bunny.jmh; package jmh;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.profile.StackProfiler; import org.openjdk.jmh.profile.StackProfiler;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import java.util.stream.Stream; import java.util.stream.Stream;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import java.util.stream.Stream; import java.util.stream.Stream;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import java.util.Comparator; import java.util.Comparator;
import java.util.Optional; import java.util.Optional;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
import lombok.Getter; import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cn.bunny.stream; package stream;
public class StreamExample23 { public class StreamExample23 {
public static void main(String[] args) { public static void main(String[] args) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
package thread_1.safe2; package thread_safe.safe2;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -21,7 +21,7 @@ public class AtomicSafe {
for (Thread t : threads) { for (Thread t : threads) {
t.join(); t.join();
} }
System.out.println(count.get()); System.out.println(count.get());
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,6 +22,7 @@
<modules> <modules>
<module>multithreading1</module> <module>multithreading1</module>
<module>multithreading_init</module> <module>multithreading_init</module>
<module>localTools</module>
</modules> </modules>
<scm> <scm>
<connection/> <connection/>