APIs for Java Developers
Go to APIs for .NET Developers (coming soon)Class DelayGcContext
- java.lang.Object
-
- com.javonet.api.DelayGcContext
-
public class DelayGcContext extends java.lang.Object
This class allows to instruct Javonet that for particular block of code all
garbage collector events should be grouped into batches and executed when batch size
reaches 100 000 objects or waits 30 seconds.Delay GC context should be used in case when huge load of short living .NET object references (NObjects)
are expected to be created in short time. Batching garbage collector events might highly increase the performance
and lower the amount of transmission between JAVA and .NET process.Delayed GC context should be considered when part of code generates huge number of calls to .NET that returns
references to other objects and performs further operations on these objects.Applicable number of calls to be classified as huge start from 500 000 NObject instances per minute. However the
solution could be applied in other cases as well if performance improvement will be detected by experiment.Important:It should be noticed that using delay GC context might cause increased memory consumption.
Delay GC context groups objects for all threads in which it was initialized in single buffer. When buffer reaches
100 000 objects or times out 30 seconds then Javonet flushes the collect events to .NET process and .NET GC collects
the objects.Usage sample
Delay GC context should be used by calling
Begin()
method before the block of code to be wrapped
andEnd()
at the end of the block. Delay GC context affects only objects created in the same thread
in which context was started.DelayGcContext.Begin(); for (int i=0; i<5000000;i++) { NObject objA = Javonet.New("SampleType",i); NObject objB = objA.get("B"); processItem(objB); (... some other operations ...) NObject objC = objB.getRef("subProp").getRef("subProp").invoke("GetC"); } DelayGcContext.End();
- Version:
- 1.4
- Author:
- Javonet
-
Constructor Summary
Constructors Constructor and Description DelayGcContext()
Delay GC context constructor can be used to wrap the block of code which should be included
in delay GC mechanism using try () { } syntax in Java 7 or higher.
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static void
Begin()
Begins delayed GC context block.static void
End()
Ends delayed GC context block.static java.lang.Boolean
getIsInContext()
-
Constructor Detail
-
DelayGcContext
public DelayGcContext()
Delay GC context constructor can be used to wrap the block of code which should be included
in delay GC mechanism using try () { } syntax in Java 7 or higher.All NObjects initialized within this block will be marked as delayed
garbage collect. When JAVA GC will try to collect these instances the collect event will be stored in temporary
buffer and flushed to .NET side when reaches hundred thousands objects or waits thirty seconds.Sample usage:
try (DelayGcContext dgc = new DelayGcContext()) { (... number of operation on NObjects ... ) }
-
Method Detail
-
Begin
public static void Begin()
Begins delayed GC context block.This method should be called before the code block where huge load of short living NObjects instances
are expected to be created. All NObjects initialized after call of this method will be marked as delayed
garbage collect. When JAVA GC will try to collect these instances the collect event will be stored in temporary
buffer and flushed to .NET side when reaches hundred thousands objects or waits thirty seconds.
-
End
public static void End()
Ends delayed GC context block.This method should be called after calling Begin() method after the block of code which should be included
in delay GC mechanism.
-
getIsInContext
public static java.lang.Boolean getIsInContext()
-