no message
This commit is contained in:
@@ -17,6 +17,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.stream.Collectors;
|
||||
public class CommonUtils {
|
||||
@@ -26,7 +27,13 @@ public class CommonUtils {
|
||||
public static String Home;
|
||||
//ГЛОБАЛЬНЫЙ ЖУРНАЛ
|
||||
public static Loggable MainLog;
|
||||
public static Semaphore date_semaphore = new Semaphore(1);
|
||||
public static long last_ticks = CommonConstants.Nan;
|
||||
//------------------------------------------------------------------------
|
||||
public static Object requireNonNullElse(Object value, Object default_value) {
|
||||
return (value != null) ? value : default_value;
|
||||
}
|
||||
//--
|
||||
//JSON
|
||||
//--
|
||||
// public static String jsonToPrettyFormat(String packed) {
|
||||
@@ -401,7 +408,41 @@ public class CommonUtils {
|
||||
public static String print_date(Date date) {
|
||||
return new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(date);
|
||||
}
|
||||
//-
|
||||
public static String printSplittedDateInterval(long milliseconds) {
|
||||
//--
|
||||
long seconds = milliseconds / 1000;
|
||||
long hours = seconds / 3600;
|
||||
seconds = seconds - hours * 3600;
|
||||
long minutes = (seconds) / 60;
|
||||
seconds = seconds - minutes * 60;
|
||||
//--
|
||||
return hours + " часов, " + minutes + " минут, " + seconds + " секунд";
|
||||
}
|
||||
//Синхронизация
|
||||
public static void sleep(long millis) {
|
||||
try {
|
||||
Thread.sleep(millis);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
//ГЕНЕРАЦИЯ ИМЕН
|
||||
|
||||
public static long getDateNumber() {
|
||||
//-
|
||||
try {
|
||||
date_semaphore.acquire();
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
//-
|
||||
long ticks = new Date().toInstant().getEpochSecond();
|
||||
while (ticks == last_ticks) {
|
||||
sleep(1);
|
||||
ticks = new Date().toInstant().getEpochSecond();
|
||||
}
|
||||
last_ticks = ticks; // Это и есть разделяемый ресурс.
|
||||
date_semaphore.release();
|
||||
return ticks;
|
||||
}
|
||||
public static String getDateName(String name_) {
|
||||
return name_ + "_" + getDateNumber();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user