api: threads, files
This commit is contained in:
27
common/src/main/java/com/stardust/concurrent/Value.java
Normal file
27
common/src/main/java/com/stardust/concurrent/Value.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.stardust.concurrent;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/12/27.
|
||||
*/
|
||||
|
||||
public class Value<T> {
|
||||
|
||||
private T mValue;
|
||||
|
||||
public Value(T value) {
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
public Value() {
|
||||
}
|
||||
|
||||
public T get() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void set(T value) {
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -10,14 +10,14 @@ import java.util.WeakHashMap;
|
||||
|
||||
public class ThreadCompat extends Thread {
|
||||
|
||||
private static volatile WeakHashMap<Thread, Boolean> interruptStatus = new WeakHashMap<>();
|
||||
// private static volatile WeakHashMap<Thread, Boolean> interruptStatus = new WeakHashMap<>();
|
||||
|
||||
public ThreadCompat() {
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
interruptStatus.put(this, false);
|
||||
// interruptStatus.put(this, false);
|
||||
}
|
||||
|
||||
public ThreadCompat(Runnable target) {
|
||||
@@ -59,23 +59,23 @@ public class ThreadCompat extends Thread {
|
||||
public void run() {
|
||||
try {
|
||||
super.run();
|
||||
interruptStatus.remove(this);
|
||||
// interruptStatus.remove(this);
|
||||
} catch (Throwable e) {
|
||||
interruptStatus.remove(this);
|
||||
// interruptStatus.remove(this);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInterrupted() {
|
||||
Boolean isInterrupted = interruptStatus.get(this);
|
||||
return super.isInterrupted() || isInterrupted == null || isInterrupted;
|
||||
//Boolean isInterrupted = interruptStatus.get(this);
|
||||
return super.isInterrupted();// || isInterrupted == null || isInterrupted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interrupt() {
|
||||
super.interrupt();
|
||||
interruptStatus.remove(this);
|
||||
//interruptStatus.put(this, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -76,6 +76,10 @@ public class PFiles {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean createWithDirs(String path) {
|
||||
return createIfNotExists(path);
|
||||
}
|
||||
|
||||
public static boolean exists(String path) {
|
||||
return new File(path).exists();
|
||||
}
|
||||
@@ -212,6 +216,7 @@ public class PFiles {
|
||||
}
|
||||
|
||||
public static void append(String path, String text) {
|
||||
create(path);
|
||||
try {
|
||||
write(new FileOutputStream(path, true), text);
|
||||
} catch (FileNotFoundException e) {
|
||||
@@ -221,6 +226,7 @@ public class PFiles {
|
||||
|
||||
|
||||
public static void append(String path, String text, String encoding) {
|
||||
create(path);
|
||||
try {
|
||||
write(new FileOutputStream(path, true), text, encoding);
|
||||
} catch (FileNotFoundException e) {
|
||||
@@ -238,6 +244,7 @@ public class PFiles {
|
||||
}
|
||||
|
||||
public static void appendBytes(String path, byte[] bytes) {
|
||||
create(path);
|
||||
try {
|
||||
writeBytes(new FileOutputStream(path, true), bytes);
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user