
|
If you were logged in you would be able to see more operations.
|
|
|
|
I've been evaluating OSCache for use on a project, and have run
across some thread safety issues, that apparently cause
memory "leaks". Attached is a very simple example that illustrates
the problem. It creates multiple threads which each use a single
GeneralCacheAdministrator object to retrieve a cache value.
When run with -verbose:gc, you will notice that memory usage
increases unbounded. The only case where this does not occur is
when the program is run with only a single thread.
This can be reproduced with the latest available version, 1.7.5.
I have been testing this on a Solaris 9, multi-processor machine.
---- Test Case ----
import com.opensymphony.module.oscache.general.*;
import com.opensymphony.module.oscache.base.*;
import com.opensymphony.module.oscache.*;
public class OSGeneralTest implements Runnable {
static GeneralCacheAdministrator admin = null;
static {
try {
admin = GeneralCacheAdministrator.getInstance();
}
catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public void run() {
for (;;) {
doit();
}
}
public void doit() {
String myKey = "myKey";
String myValue;
int myRefreshPeriod = 60 /*seconds*/ * 1000 /*millis*/;
try {
// Get from the cache
myValue = (String) admin.getFromCache(myKey, myRefreshPeriod);
}
catch (NeedsRefreshException nre) {
try {
// Get the value (probably by calling an EJB)
myValue = "This is the content retrieved.";
// Store in the cache
admin.putInCache(myKey, myValue);
System.err.println("Put in cache");
}
catch (Exception ex) {
// We have the current content if we want fail-over.
myValue = (String) nre.getCacheContent();
}
}
}
public static void main(String[] args) {
if (args.length <= 0) {
System.err.println("usage: java OSGeneralTest <threads>");
System.exit(1);
}
for (int idx = 0; idx < Integer.parseInt(args[0]); idx++) {
OSGeneralTest runner = new OSGeneralTest();
Thread thread = new Thread(runner);
thread.start();
}
}
}
|
|
Description
|
I've been evaluating OSCache for use on a project, and have run
across some thread safety issues, that apparently cause
memory "leaks". Attached is a very simple example that illustrates
the problem. It creates multiple threads which each use a single
GeneralCacheAdministrator object to retrieve a cache value.
When run with -verbose:gc, you will notice that memory usage
increases unbounded. The only case where this does not occur is
when the program is run with only a single thread.
This can be reproduced with the latest available version, 1.7.5.
I have been testing this on a Solaris 9, multi-processor machine.
---- Test Case ----
import com.opensymphony.module.oscache.general.*;
import com.opensymphony.module.oscache.base.*;
import com.opensymphony.module.oscache.*;
public class OSGeneralTest implements Runnable {
static GeneralCacheAdministrator admin = null;
static {
try {
admin = GeneralCacheAdministrator.getInstance();
}
catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public void run() {
for (;;) {
doit();
}
}
public void doit() {
String myKey = "myKey";
String myValue;
int myRefreshPeriod = 60 /*seconds*/ * 1000 /*millis*/;
try {
// Get from the cache
myValue = (String) admin.getFromCache(myKey, myRefreshPeriod);
}
catch (NeedsRefreshException nre) {
try {
// Get the value (probably by calling an EJB)
myValue = "This is the content retrieved.";
// Store in the cache
admin.putInCache(myKey, myValue);
System.err.println("Put in cache");
}
catch (Exception ex) {
// We have the current content if we want fail-over.
myValue = (String) nre.getCacheContent();
}
}
}
public static void main(String[] args) {
if (args.length <= 0) {
System.err.println("usage: java OSGeneralTest <threads>");
System.exit(1);
}
for (int idx = 0; idx < Integer.parseInt(args[0]); idx++) {
OSGeneralTest runner = new OSGeneralTest();
Thread thread = new Thread(runner);
thread.start();
}
}
}
|
Show » |
|