sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/03: Clarification in javadoc.
Date Sat, 19 Oct 2019 11:13:44 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit bdce53dfc40a2021110be335ee02b4172ef0f72a
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Oct 18 16:18:32 2019 +0200

    Clarification in javadoc.
---
 .../java/org/apache/sis/internal/system/DaemonThread.java   |  4 +++-
 .../main/java/org/apache/sis/util/collection/WeakEntry.java | 13 +++++++------
 .../java/org/apache/sis/util/collection/WeakHashSet.java    |  7 ++++++-
 .../org/apache/sis/util/collection/WeakValueHashMap.java    |  7 ++++++-
 4 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/system/DaemonThread.java
b/core/sis-utility/src/main/java/org/apache/sis/internal/system/DaemonThread.java
index 136293c..b1f2801 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/system/DaemonThread.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/system/DaemonThread.java
@@ -59,6 +59,8 @@ abstract class DaemonThread extends Thread {
 
     /**
      * Creates a new daemon thread. This constructor sets the daemon flag to {@code true}.
+     * The thread will be allocated a small stack size on the assumption that it will execute
+     * only small and quick methods, without deep nesting levels.
      *
      * <p>We need to maintain a list of daemon threads created by each SIS module in
order to
      * kill them at shutdown time (not strictly necessary for pure JSEE applications, but
@@ -88,7 +90,7 @@ abstract class DaemonThread extends Thread {
      *                            Each SIS module shall maintain its own chain, if any.
      */
     protected DaemonThread(final String name, final DaemonThread lastCreatedDaemon) {
-        super(Threads.DAEMONS, name);
+        super(Threads.DAEMONS, null, name, 16*1024);    // Small (16 kb) stack size.
         previous = lastCreatedDaemon;
         setDaemon(true);
     }
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
index cfcf10f..9665ca4 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakEntry.java
@@ -57,11 +57,11 @@ abstract class WeakEntry<E> extends WeakReference<E> implements
Disposable {
 
     /**
      * Number of nanoseconds to wait before to rehash the table for reducing its size.
-     * When the garbage collector collects a lot of elements, we will at least this amount
of time
-     * before rehashing the tables, in case lot of news elements are going to be added. Without
this
-     * field, we noticed many "reduce", "expand", "reduce", "expand", <i>etc.</i>
cycles.
+     * When the garbage collector collects a lot of elements, we will wait at least this
amount of time
+     * before to rehash the tables, in case lot of news elements are going to be added. We
noticed that
+     * in the absence of delay, there is a lot of "reduce", "expand", "reduce", "expand",
<i>etc.</i> cycles.
      */
-    static final long REHASH_DELAY = 4000000000L;
+    static final long REHASH_DELAY = 4000_000_000L;                     // 4 seconds.
 
     /**
      * The logger where to logs collection events, if logging at the finest level is enabled.
@@ -70,6 +70,7 @@ abstract class WeakEntry<E> extends WeakReference<E> implements
Disposable {
 
     /**
      * The next entry, or {@code null} if there is none.
+     * This is used when more than one entry has the same hash code value.
      */
     WeakEntry<E> next;
 
@@ -123,7 +124,7 @@ abstract class WeakEntry<E> extends WeakReference<E> implements
Disposable {
                 } else {
                     table[removeAt] = e.next;
                 }
-                // We can't continue the loop pass that point, since 'e' is no longer valid.
+                // We can not continue the loop pass that point, since `e` is no longer valid.
                 return true;
             }
             prev = e;
@@ -165,7 +166,7 @@ abstract class WeakEntry<E> extends WeakReference<E> implements
Disposable {
         for (WeakEntry<E> next : oldTable) {
             while (next != null) {
                 final WeakEntry<E> e = next;
-                next = next.next;                           // We keep 'next' right now because
its value will change.
+                next = next.next;                           // Fetch `next` now because its
value will change.
                 final int index = e.hash % table.length;
                 e.next = table[index];
                 table[index] = e;
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakHashSet.java
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakHashSet.java
index c735c7e..c4b404f 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakHashSet.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakHashSet.java
@@ -107,7 +107,8 @@ public class WeakHashSet<E> extends AbstractSet<E> implements
CheckedContainer<E
     private Entry[] table;
 
     /**
-     * Number of non-null elements in {@link #table}.
+     * Number of non-null elements in {@link #table}. This is used for determining
+     * when {@link WeakEntry#rehash(WeakEntry[], int, String)} needs to be invoked.
      */
     private int count;
 
@@ -161,6 +162,8 @@ public class WeakHashSet<E> extends AbstractSet<E> implements
CheckedContainer<E
     /**
      * Invoked by {@link Entry} when an element has been collected by the garbage
      * collector. This method removes the weak reference from the {@link #table}.
+     *
+     * @param  toRemove  the entry to remove from this map.
      */
     private synchronized void removeEntry(final Entry toRemove) {
         assert isValid();
@@ -182,6 +185,8 @@ public class WeakHashSet<E> extends AbstractSet<E> implements
CheckedContainer<E
     /**
      * Checks if this {@code WeakHashSet} is valid. This method counts the number of elements
and
      * compares it to {@link #count}. This method is invoked in assertions only.
+     *
+     * @return whether {@link #count} matches the expected value.
      */
     @Debug
     private boolean isValid() {
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java
index c550061..119bbd3 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java
@@ -196,7 +196,8 @@ public class WeakValueHashMap<K,V> extends AbstractMap<K,V>
{
     private Entry[] table;
 
     /**
-     * Number of non-null elements in {@link #table}.
+     * Number of non-null elements in {@link #table}. This is used for determining
+     * when {@link WeakEntry#rehash(WeakEntry[], int, String)} needs to be invoked.
      */
     private int count;
 
@@ -271,6 +272,8 @@ public class WeakValueHashMap<K,V> extends AbstractMap<K,V>
{
     /**
      * Invoked by {@link Entry} when an element has been collected by the garbage
      * collector. This method removes the weak reference from the {@link #table}.
+     *
+     * @param  toRemove  the entry to remove from this map.
      */
     @SuppressWarnings("unchecked")
     private synchronized void removeEntry(final Entry toRemove) {
@@ -293,6 +296,8 @@ public class WeakValueHashMap<K,V> extends AbstractMap<K,V>
{
     /**
      * Checks if this {@code WeakValueHashMap} is valid. This method counts the number of
elements
      * and compares it to {@link #count}. This method is invoked in assertions only.
+     *
+     * @return whether {@link #count} matches the expected value.
      */
     @Debug
     final boolean isValid() {


Mime
View raw message