Alachisoft.NCache.Common.Stats.GarbageCollectionTask Maven / Gradle / Ivy
package Alachisoft.NCache.Common.Stats;
public final class GarbageCollectionTask {
//implements TimeScheduler.Task {
// private static final int _maxFilureCount = 5;
// private static final int _minCollectionInterval = 5; ///5 seconds
//
// /** Interval after which the task will be executed agian
// */
// private int _executionInterval = 20000; //20 seconds
//
// /** Total memory available (in bytes)
// */
////C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
////ORIGINAL LINE: private ulong _totalMemory = 0;
// private long _totalMemory = 0;
//
// /** Usage threshold, after which GC will be invoked
// */
// private int _collectionThreshold;
//
// /** Cancel the task
// */
// private boolean _cancel = false;
//
// /** Number of times the execution of task failed
// */
// private short _failureCount = 0;
//
// public GarbageCollectionTask(int collectionThreshold) {
// this._collectionThreshold = collectionThreshold;
//
// String intervalSettings = ConfigurationSettings.AppSettings["NCacheServer.ForcedGCInterval"];
// if (!tangible.DotNetToJavaStringHelper.isNullOrEmpty(intervalSettings)) {
// tangible.RefObject tempRef__executionInterval = new tangible.RefObject(this._executionInterval);
// Integer.pa(intervalSettings, tempRef__executionInterval);
// this._executionInterval = tempRef__executionInterval.argvalue;
// if (this._executionInterval < _minCollectionInterval) {
// this._executionInterval = _minCollectionInterval;
// }
// this._executionInterval *= 1000; ///Convert to milliseconds
// }
// }
//
////C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
// ///#region Task Members
//
// public boolean IsCancelled() {
// return this._cancel;
// }
//
// public long GetNextInterval() {
// return _executionInterval;
// }
//
// public void Run() {
// if (this._totalMemory <= 0) {
// this._totalMemory = this.GetSystemMemory();
// if (this._totalMemory <= 0) {
// return;
// }
// }
//
// /**[Ata]This call take some time to complete.
// Benchmark @Quad core, 8GB RAM, 1,000,000 iterations
// Best(ms): 0.2366, Avg(ms): 0.3188, Worst(ms): 23.6123
// */
////C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
////ORIGINAL LINE: ulong processUsage = (ulong)Process.GetCurrentProcess().PrivateMemorySize64;
// long processUsage = (long)Process.GetCurrentProcess().PrivateMemorySize64;
//
// float usage = ((float)processUsage / this._totalMemory) * 100;
//
// if (usage >= this._collectionThreshold) {
// GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
// }
// }
//
////C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
// ///#endregion
//
// /**
// Get system's total memory
//
// @return System's total memory
// */
// private long GetSystemMemory() {
// /**Retrieve system memory information
// */
// MemoryStatus.MemoryStatusEx status = new MemoryStatus.MemoryStatusEx();
// try {
// /**This call is quiet effiecient. Also, it is called only once if we
// successfully retrieve system memory information (otherwise we will retry
// every time the task is invoked until we reach the failure count)
// Benchmark @Quad core, 8GB RAM, 1,000,000 iterations
// Best(ms): 0.003821, Avg(ms): 0.004136, Worst(ms): 0.5701
// */
// status = MemoryStatus.GetMemoryStatus();
//
// /**Unable to retrieve system memory status
// */
// if (status.TotalMemory <= 0) {
// //this._context.CacheTrace.error("Cache.StartGCTask",
// // "Failed to retrieve memory status. Garbage collection task will not start");
// this._failureCount++;
//
// return 0;
// }
//
// return status.TotalMemory;
// } catch (RuntimeException exc) {
// //this._context.CacheTrace.error("Cache.StartGCTask",
// // string.Format("An exception occurred while retrieving system memory information. Exception: {0}",
// // exc.ToString()));
// this._failureCount++;
//
// return 0;
// } finally {
//
// if (this._failureCount >= _maxFilureCount) {
// AppUtil.LogEvent("NCache", "Failed to retrieve memory status. Garbage collection task will now exit", EventLogEntryType.Error, EventCategories.Error, EventID.GeneralError);
//
// this._cancel = true;
// }
// }
// }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy