Recent Notes

Displaying keyword search results 1 - 2
Created by alfa on June 07, 2011 11:34:26    Last update: June 07, 2011 11:36:37
This is an example that uses dynamic proxies to trace method calls (in logging) and print out elapsed times for them. Because dynamic proxies can only be generated for interfaces, the service classes must be implemented with interface-implementation pairs. Create services A and B. A.java : public interface A { public void service1()... AImpl.java : import java.util.Random; public class AImpl... B.java : public interface B { public void service1()... BImpl.java : public class BImpl implements B { public vo... The call trace proxy: import java.lang.reflect.*; class TraceProx... The performance proxy: import java.lang.reflect.*; class Performan... The service factory: import java.lang.reflect.*; public class Se... The test class: public class Test { public static void main... The output: Entering AImpl.service1 Entering BImpl.service1... The above example has no information...
Created by alfa on June 03, 2011 12:36:14    Last update: June 03, 2011 12:36:14
Thread local storage is typically used to associate state with a thread (e.g., a user ID or Transaction ID). This example, coming from Java API doc , assigns a unique id to each thread that calls getCurrentThreadId() . The actual usage is demonstrated with the Java concurrency package. import java.util.concurrent.Future; import java...