java:java
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
java:java [2022/07/26 07:18] – [Thread pools] admin | java:java [2024/05/31 05:22] (current) – [Random in Java] admin | ||
---|---|---|---|
Line 401: | Line 401: | ||
// so add 1 to make it inclusive | // so add 1 to make it inclusive | ||
ThreadLocalRandom.current().nextInt(min, | ThreadLocalRandom.current().nextInt(min, | ||
+ | </ | ||
+ | ==== Md5 ==== | ||
+ | <code java> | ||
+ | import java.util.HashMap; | ||
+ | import java.security.MessageDigest; | ||
+ | public static String md5(String original) { | ||
+ | try{ | ||
+ | MessageDigest md = MessageDigest.getInstance(" | ||
+ | md.update(original.getBytes()); | ||
+ | byte[] digest = md.digest(); | ||
+ | StringBuffer sb = new StringBuffer(); | ||
+ | for (byte b : digest) { | ||
+ | sb.append(String.format(" | ||
+ | } | ||
+ | return sb.toString(); | ||
+ | }catch(Exception e){ | ||
+ | return ""; | ||
+ | } | ||
+ | } | ||
</ | </ | ||
==== Java Reflection ==== | ==== Java Reflection ==== | ||
Line 562: | Line 581: | ||
* **Atomic variables** have features that minimize synchronization and help avoid memory consistency errors. | * **Atomic variables** have features that minimize synchronization and help avoid memory consistency errors. | ||
* **ThreadLocalRandom** (in JDK 7) provides **efficient generation of pseudorandom numbers from multiple threads**. | * **ThreadLocalRandom** (in JDK 7) provides **efficient generation of pseudorandom numbers from multiple threads**. | ||
- | === Executor Interfaces === | + | |
- | === Thread pools === | + | ==== Thread pools ==== |
+ | {{: | ||
refer: | refer: | ||
- | * https:// | ||
- | * http:// | ||
* https:// | * https:// | ||
* http:// | * http:// | ||
+ | * http:// | ||
Thread pools address two different problems: | Thread pools address two different problems: | ||
* They usually provide improved performance when **executing large numbers of asynchronous tasks**, due to reduced per-task invocation overhead | * They usually provide improved performance when **executing large numbers of asynchronous tasks**, due to reduced per-task invocation overhead |
java/java.1658819918.txt.gz · Last modified: 2022/10/29 16:15 (external edit)