Skip to content

Commit

Permalink
🔖 版本升级xml, javax.xml.bind.-> jakarta.xml.bind.
Browse files Browse the repository at this point in the history
  • Loading branch information
lunasaw committed Apr 10, 2024
1 parent da3ecd9 commit 3aad8a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 40 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/luna/common/cache/SimpleGuavaCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSON;
import com.google.common.cache.*;
import com.google.common.collect.ImmutableMap;

Expand Down Expand Up @@ -66,7 +67,8 @@ public void put(K key, V value) {
cache.put(key, value);
}

public void invalidate(K... key) {
@SafeVarargs
public final void invalidate(K... key) {
Arrays.stream(key).forEach(cache::invalidate);
}

Expand Down Expand Up @@ -102,7 +104,8 @@ public void refresh(K key) {
cache.refresh(key);
}

public ImmutableMap<K, V> getAllPresent(K... keys) {
@SafeVarargs
public final ImmutableMap<K, V> getAllPresent(K... keys) {
return cache.getAllPresent(Arrays.stream(keys).distinct().collect(Collectors.toList()));
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/luna/common/xml/JAXBUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import java.io.StringWriter;
import java.nio.charset.Charset;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.Unmarshaller;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlTransient;

import com.luna.common.file.FileTools;
import com.luna.common.io.IoUtil;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/luna/common/xml/XmlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.*;

import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.Unmarshaller;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.parsers.*;
Expand Down
46 changes: 18 additions & 28 deletions src/test/java/com/luna/common/utils/GuavaCacheTest.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,38 @@
package com.luna.common.utils;

import java.util.concurrent.Callable;

import com.google.common.cache.CacheLoader;
import com.luna.common.cache.SimpleGuavaCache;

public class GuavaCacheTest {

private static final SimpleGuavaCache<String, String> cache = new SimpleGuavaCache<String, String>(new CacheLoader<String, String>() {
private static final SimpleGuavaCache<String, String> cache = new SimpleGuavaCache<>(new CacheLoader<String, String>() {
public String load(String key) throws Exception {
System.out.println("load data"); // 加载数据线程执行标志
Thread.sleep(1000); // 模拟加载时间
return "auto load by CacheLoader";
}
});

public static void main(String[] args) throws InterruptedException {
public static void main(String[] args) {

new Thread(new Runnable() {
public void run() {
System.out.println("thread1");
String value = cache.get("key", new Callable<String>() {
public String call() throws Exception {
System.out.println("load1"); // 加载数据线程执行标志
Thread.sleep(1000); // 模拟加载时间
return "auto load by Callable";
}
});
System.out.println("thread1 " + value);
}
new Thread(() -> {
System.out.println("thread1");
String value = cache.get("key", () -> {
System.out.println("load1"); // 加载数据线程执行标志
Thread.sleep(1000); // 模拟加载时间
return "auto load by Callable";
});
System.out.println("thread1 " + value);
}).start();

new Thread(new Runnable() {
public void run() {
System.out.println("thread2");
String value = cache.get("key", new Callable<String>() {
public String call() throws Exception {
System.out.println("load2"); // 加载数据线程执行标志
Thread.sleep(1000); // 模拟加载时间
return "auto load by Callable";
}
});
System.out.println("thread2 " + value);
}
new Thread(() -> {
System.out.println("thread2");
String value = cache.get("key", () -> {
System.out.println("load2"); // 加载数据线程执行标志
Thread.sleep(1000); // 模拟加载时间
return "auto load by Callable";
});
System.out.println("thread2 " + value);
}).start();
}
}

0 comments on commit 3aad8a6

Please sign in to comment.