Skip to content

Commit dad0be2

Browse files
author
lijun695
committed
增加新代码
1 parent 1c4f4a9 commit dad0be2

File tree

6 files changed

+146
-0
lines changed

6 files changed

+146
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.diguage.truman.concurrent;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.concurrent.ConcurrentHashMap;
6+
import java.util.concurrent.ConcurrentMap;
7+
import java.util.concurrent.atomic.AtomicInteger;
8+
9+
public class ConcurrentMapTest {
10+
@Test
11+
public void test() {
12+
ConcurrentMap<String, AtomicInteger> map = new ConcurrentHashMap<>();
13+
// AtomicInteger cnt = map.putIfAbsent("abc", new AtomicInteger(10));
14+
AtomicInteger cnt = map.computeIfAbsent("abc", (k) -> new AtomicInteger(10));
15+
System.out.println(cnt);
16+
}
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.diguage.truman.concurrent;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.time.LocalDateTime;
6+
import java.util.concurrent.ScheduledExecutorService;
7+
import java.util.concurrent.ScheduledThreadPoolExecutor;
8+
import java.util.concurrent.TimeUnit;
9+
import java.util.concurrent.locks.LockSupport;
10+
11+
public class ScheduledThreadPoolExecutorTest {
12+
@Test
13+
public void test() {
14+
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(0);
15+
executor.scheduleAtFixedRate(() -> System.out.println("OKKK"), 0, 10, TimeUnit.MINUTES);
16+
LockSupport.parkNanos(TimeUnit.MINUTES.toNanos(1));
17+
System.out.println(executor);
18+
}
19+
20+
@Test
21+
public void testSchedule() {
22+
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(0);
23+
for (int i = 0; i < 100; i++) {
24+
executor.schedule(() -> System.out.println(LocalDateTime.now() + " OKKK"), 0, TimeUnit.MINUTES);
25+
}
26+
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(10));
27+
System.out.println(executor);
28+
}
29+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.diguage.truman.io;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.io.File;
6+
import java.io.IOException;
7+
import java.nio.charset.StandardCharsets;
8+
import java.nio.file.Files;
9+
import java.nio.file.Paths;
10+
import java.time.ZoneId;
11+
import java.time.format.DateTimeFormatter;
12+
import java.util.Date;
13+
14+
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
15+
16+
public class FileTest {
17+
18+
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
19+
20+
@Test
21+
public void test() {
22+
File file = new File("/Users/lijun695/vm.log");
23+
long mod = file.lastModified();
24+
System.out.println(new Date(mod).toInstant().atZone(ZoneId.systemDefault()));
25+
System.out.println(file.getName());
26+
}
27+
28+
public static void main(String[] args) throws IOException {
29+
for (int i = 0; i < 10; i++) {
30+
Files.write(Paths.get("/tmp/abc123/456/20230609183256983"),
31+
("" + i + " -- D瓜哥 · https://www.diguage.com").getBytes(StandardCharsets.UTF_8), TRUNCATE_EXISTING);
32+
}
33+
}
34+
35+
public static void createDirectory(String path) {
36+
File file = new File(path);
37+
if (file.exists() && !file.isDirectory()) {
38+
file.delete();
39+
}
40+
if (!file.exists()) {
41+
try {
42+
Files.createDirectories(Paths.get(path));
43+
} catch (IOException e) {
44+
e.printStackTrace();
45+
}
46+
}
47+
}
48+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.diguage.truman.math;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.math.BigDecimal;
6+
7+
public class BigDecimalTest {
8+
@Test
9+
public void test() {
10+
BigDecimal decimal = new BigDecimal("10.");
11+
System.out.println(decimal);
12+
}
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.diguage.truman.time;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.time.Duration;
6+
import java.time.LocalDateTime;
7+
import java.time.ZoneId;
8+
import java.time.ZonedDateTime;
9+
import java.time.format.DateTimeFormatter;
10+
11+
public class FormatTest {
12+
13+
@Test
14+
public void test() {
15+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
16+
// ZonedDateTime time = ZonedDateTime.parse("20230815114735092", formatter);
17+
LocalDateTime t3 = LocalDateTime.parse("20230609143033001", formatter);
18+
LocalDateTime t1 = LocalDateTime.parse("20230815114735092", formatter);
19+
LocalDateTime t2 = LocalDateTime.parse("20230815114735099", formatter);
20+
System.out.println();
21+
}
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.diguage.truman.time;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.time.ZoneId;
6+
import java.time.ZonedDateTime;
7+
import java.time.temporal.ChronoUnit;
8+
9+
public class ZoneTest {
10+
@Test
11+
public void test() {
12+
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
13+
ZonedDateTime tomorrow = now.plusDays(1L).truncatedTo(ChronoUnit.DAYS).plusHours(5L);
14+
System.out.println(now);
15+
System.out.println(tomorrow);
16+
}
17+
}

0 commit comments

Comments
 (0)