-
Notifications
You must be signed in to change notification settings - Fork 100
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
lijun695
committed
May 27, 2024
1 parent
1c4f4a9
commit dad0be2
Showing
6 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/main/java/com/diguage/truman/concurrent/ConcurrentMapTest.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,17 @@ | ||
package com.diguage.truman.concurrent; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class ConcurrentMapTest { | ||
@Test | ||
public void test() { | ||
ConcurrentMap<String, AtomicInteger> map = new ConcurrentHashMap<>(); | ||
// AtomicInteger cnt = map.putIfAbsent("abc", new AtomicInteger(10)); | ||
AtomicInteger cnt = map.computeIfAbsent("abc", (k) -> new AtomicInteger(10)); | ||
System.out.println(cnt); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/diguage/truman/concurrent/ScheduledThreadPoolExecutorTest.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,29 @@ | ||
package com.diguage.truman.concurrent; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.locks.LockSupport; | ||
|
||
public class ScheduledThreadPoolExecutorTest { | ||
@Test | ||
public void test() { | ||
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(0); | ||
executor.scheduleAtFixedRate(() -> System.out.println("OKKK"), 0, 10, TimeUnit.MINUTES); | ||
LockSupport.parkNanos(TimeUnit.MINUTES.toNanos(1)); | ||
System.out.println(executor); | ||
} | ||
|
||
@Test | ||
public void testSchedule() { | ||
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(0); | ||
for (int i = 0; i < 100; i++) { | ||
executor.schedule(() -> System.out.println(LocalDateTime.now() + " OKKK"), 0, TimeUnit.MINUTES); | ||
} | ||
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(10)); | ||
System.out.println(executor); | ||
} | ||
} |
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,48 @@ | ||
package com.diguage.truman.io; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Date; | ||
|
||
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; | ||
|
||
public class FileTest { | ||
|
||
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"); | ||
|
||
@Test | ||
public void test() { | ||
File file = new File("/Users/lijun695/vm.log"); | ||
long mod = file.lastModified(); | ||
System.out.println(new Date(mod).toInstant().atZone(ZoneId.systemDefault())); | ||
System.out.println(file.getName()); | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
for (int i = 0; i < 10; i++) { | ||
Files.write(Paths.get("/tmp/abc123/456/20230609183256983"), | ||
("" + i + " -- D瓜哥 · https://www.diguage.com").getBytes(StandardCharsets.UTF_8), TRUNCATE_EXISTING); | ||
} | ||
} | ||
|
||
public static void createDirectory(String path) { | ||
File file = new File(path); | ||
if (file.exists() && !file.isDirectory()) { | ||
file.delete(); | ||
} | ||
if (!file.exists()) { | ||
try { | ||
Files.createDirectories(Paths.get(path)); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
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,13 @@ | ||
package com.diguage.truman.math; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class BigDecimalTest { | ||
@Test | ||
public void test() { | ||
BigDecimal decimal = new BigDecimal("10."); | ||
System.out.println(decimal); | ||
} | ||
} |
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,22 @@ | ||
package com.diguage.truman.time; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class FormatTest { | ||
|
||
@Test | ||
public void test() { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"); | ||
// ZonedDateTime time = ZonedDateTime.parse("20230815114735092", formatter); | ||
LocalDateTime t3 = LocalDateTime.parse("20230609143033001", formatter); | ||
LocalDateTime t1 = LocalDateTime.parse("20230815114735092", formatter); | ||
LocalDateTime t2 = LocalDateTime.parse("20230815114735099", formatter); | ||
System.out.println(); | ||
} | ||
} |
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,17 @@ | ||
package com.diguage.truman.time; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class ZoneTest { | ||
@Test | ||
public void test() { | ||
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Shanghai")); | ||
ZonedDateTime tomorrow = now.plusDays(1L).truncatedTo(ChronoUnit.DAYS).plusHours(5L); | ||
System.out.println(now); | ||
System.out.println(tomorrow); | ||
} | ||
} |