Weird,
I expected the volatile to make it run slower.
The JVM has to check the reference to Category
on every operation.
hprof says this is true, but for some reason
the method invoked through the Category takes less
time?
[pre]
CPU TIME (ms) BEGIN (total = 41544) Wed Feb 27 13:42:01 2002
rank self accum count trace method
1 19.96% 19.96% 2000000 51 org.apache.log4j.Category.debug (Wrapper)
2 19.48% 39.43% 2000000 40 org.apache.log4j.Category.debug (WrapperVolatile)
3 10.32% 49.75% 2000000 46 Vol$WrapperVolatile.debug
4 9.98% 59.73% 2000000 24 Vol$Wrapper.debug
5 9.35% 69.08% 2000000 44 org.apache.log4j.Category.getChainedPriority (Wrapper)
6 8.77% 77.85% 2000000 45 org.apache.log4j.Category.getChainedPriority
(WrapperVolatile)
7 6.97% 84.82% 2000000 26 org.apache.log4j.Priority.isGreaterOrEqual
(WrapperVolatile)
8 6.41% 91.23% 2000000 23 org.apache.log4j.Priority.isGreaterOrEqual (Wrapper)
Wrapper : 45.70%
WrapperVolatile : 44.98%
[/pre]
The volatile test is always quicker.
There must be problem with my test program!
[pre]
import org.apache.log4j.Category;
public class Vol
{
public static void main(String[] args)
{
org.apache.log4j.BasicConfigurator.configure();
testWrapper();
testVolatile();
}
public static void testWrapper()
{
long begin = 0;
long end = 0;
// If the JIT is going to optimize do it before the test
Wrapper x = new Wrapper("test");
for (int i=0; i < 1000000; i++)
{
x.debug("Hello");
}
// Run the non-volatile test
begin = System.currentTimeMillis();
for (int i=0; i < 100000000; i++)
{
x.debug("Hello");
}
end = System.currentTimeMillis();
System.out.println("Wrapper: " + (end-begin));
}
public static void testVolatile()
{
long begin = 0;
long end = 0;
// If the JIT is going to optimize do it before the test
WrapperVolatile v = new WrapperVolatile("test");
for (int i=0; i < 1000000; i++)
{
v.debug("Hello");
}
// Run the volatile test
begin = System.currentTimeMillis();
for (int i=0; i < 100000000; i++)
{
v.debug("Hello");
}
end = System.currentTimeMillis();
System.out.println("Volatile: " + (end-begin));
}
public static class Wrapper
{
private Category cat;
public Wrapper(String name)
{
cat = Category.getInstance(name);
cat.setPriority(org.apache.log4j.Priority.ERROR);
}
public void debug(String x)
{
cat.debug(x);
}
}
public static class WrapperVolatile
{
private volatile Category cat;
public WrapperVolatile(String name)
{
cat = Category.getInstance(name);
cat.setPriority(org.apache.log4j.Priority.ERROR);
}
public void debug(String x)
{
cat.debug(x);
}
}
}
[/pre]
Regards,
Adrian
> I did not mean to check this is. It is a
> serializable Logger. I sent
> email before about if there were any objections and
> did not hear any.
> Should I leave it or rollback?
>
> --jason
>
>
> _______________________________________________
> Jboss-development mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-dev
> lopment
_________________________________________________________
View thread online: http://main.jboss.org/thread.jsp?forum=66&thread=9773
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development