jonasforssell@yahoo.se wrote:
Hello Experts,
The 1.4 API has a few very useful functions like
Runnable.getNumberOfProcessors()
Is it possible to write a program which uses these if possible but does
not demand a 1.4 JRE and disables the feature if run on an 1.2 JRE?
If so, how would an example look like?
Thanks
/Jonas Forssell, Gothenburg, Sweden
How about reflection?
try {
Method m = Runtime.class.getDeclaredMethod(
"availableProcessors",new Class[0]);
Object o = m.invoke(Runtime.getRuntime(),new Object[0]);
return ((Integer)o).intValue();
} catch (NoSuchMethodException e) {
return 1;
}
You will need more exception handling. The NoSuchMethodException block
should return whatever number of processors you want to assume in the
1.2 JRE.
Patricia
Excellent proposal.