- ProgressHandler Threadsafe gemacht
- ermögliche loggen ohne progress, rein Zeitbasiert -> möglichst, sodass kein spam entsteht bzw. das reguläre Loggen berücksichtigt wird
This commit is contained in:
		@@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					package de.vorsorge.theo.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.math.BigDecimal;
 | 
					import java.math.BigDecimal;
 | 
				
			||||||
import java.math.RoundingMode;
 | 
					import java.math.RoundingMode;
 | 
				
			||||||
@@ -65,7 +67,7 @@ public class FabianUtil {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      protected BigDecimal getCounter() {
 | 
					      protected synchronized BigDecimal getCounter() {
 | 
				
			||||||
         return counter;
 | 
					         return counter;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -76,7 +78,7 @@ public class FabianUtil {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      protected void tick() {
 | 
					      protected synchronized void tick() {
 | 
				
			||||||
         counter = counter.add(BigDecimal.ONE);
 | 
					         counter = counter.add(BigDecimal.ONE);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -87,14 +89,14 @@ public class FabianUtil {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      public void logIf() {
 | 
					      public synchronized void logIf() {
 | 
				
			||||||
         if (counter.remainder(logDistance).signum() == 0 || isBored()) {
 | 
					         if (counter.remainder(logDistance).signum() == 0 || isBored()) {
 | 
				
			||||||
            log();
 | 
					            log();
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      private boolean isBored() {
 | 
					      private synchronized boolean isBored() {
 | 
				
			||||||
         ZonedDateTime time = lastLoggedAt == null ? startTime : lastLoggedAt;
 | 
					         ZonedDateTime time = lastLoggedAt == null ? startTime : lastLoggedAt;
 | 
				
			||||||
         return time.until(ZonedDateTime.now(), ChronoUnit.SECONDS) >= timeLogDistance;
 | 
					         return time.until(ZonedDateTime.now(), ChronoUnit.SECONDS) >= timeLogDistance;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -107,12 +109,12 @@ public class FabianUtil {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      protected void updateLastLoggedAt() {
 | 
					      protected synchronized void updateLastLoggedAt() {
 | 
				
			||||||
         lastLoggedAt = ZonedDateTime.now();
 | 
					         lastLoggedAt = ZonedDateTime.now();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      protected Duration getTimePassed() {
 | 
					      protected synchronized Duration getTimePassed() {
 | 
				
			||||||
         return Duration.ofSeconds(startTime.until(ZonedDateTime.now(), ChronoUnit.SECONDS));
 | 
					         return Duration.ofSeconds(startTime.until(ZonedDateTime.now(), ChronoUnit.SECONDS));
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -127,7 +129,7 @@ public class FabianUtil {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      public void logFinal() {
 | 
					      public synchronized void logFinal() {
 | 
				
			||||||
         Duration timePassed = getTimePassed();
 | 
					         Duration timePassed = getTimePassed();
 | 
				
			||||||
         System.out.println(counter + " Stück (100 %) erledigt. " + formatDuration(timePassed) + " vergangen.");
 | 
					         System.out.println(counter + " Stück (100 %) erledigt. " + formatDuration(timePassed) + " vergangen.");
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -178,6 +180,11 @@ public class FabianUtil {
 | 
				
			|||||||
             + formatDuration(timePassed) + " vergangen" + remainingTimePart + ".");
 | 
					             + formatDuration(timePassed) + " vergangen" + remainingTimePart + ".");
 | 
				
			||||||
         updateLastLoggedAt();
 | 
					         updateLastLoggedAt();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      public void logContinuouslyTimeBased() {
 | 
				
			||||||
 | 
					         new Thread(this::logIf).start();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user