跳至主要内容

博文

目前显示的是 六月, 2017的博文

ClassLoading In JavaEE

Today, we are going to talk about class loader in the JavaEE environment. We start from the normal ClassLoader hierarchy in JavaSE application, then analyze the differences between JavaEE. ClassLoader Hierarchy In a normal JavaSE application, we have three levels of ClassLoader: Boostrap ClassLoader Extension ClassLoader System ClassLoader Because all classes in Java are loaded by ClassLoader, we have to solve the problem: how is the first class in Java loaded? The answer is simple if we jump out of the scope of a single language. The first class in Java is loaded by a c++ ClassLoader, and because its this functionality, it is called ‘Boostrap’ ClassLoader. Besides the first class, all the classes of Java core library are all loaded by this ClassLoader in the aim of security. Extension ClassLoader, as it name indicates, is used to load installed extensions under lib/ext of jdk home. System ClassLoader, on the other hand, is used to load application specific classe...

RabbitMQ Learning (3): Example

We have talked about the basic concepts of rabbitmq and a sample of application . Now, in this blog, we will show some working code about how to config and send/receive message. (Notice this blog is mainly composed of code, you may would like to open you IDE and type/clone code and run it along the blog). Pure Java If we use pure java code, we can do like following: // set up connection CachingConnectionFactory cf = new CachingConnectionFactory( "host" , 5672 ); cf . setUsername( "timer" ); cf . setPassword( "xxx" ); cf . setVirtualHost( "timer_host" ); // set up the queue, exchange, binding on the broker RabbitAdmin admin = new RabbitAdmin(cf); Queue queue = new Queue ( "timerServer" ); admin . declareQueue( queue ); TopicExchange exchange = new TopicExchange( "timerExchange" ); admin . declareExchange(exchange); admin . declareBinding(BindingBuilder . bind( queue ) . to (exchange) . with ( "timer.*...

Log4j Conditional Log

Basic Log Log4j is a very common log library for Java, which can has most common features that we need: configure log target: file, console, network etc; configure log format: layout, pattern; configure log threshold; Property File Config Example The following is a sample config: log4j.rootLogger=CONSOLE,E log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Target=System.out log4j.appender.CONSOLE.Threshold = Warn log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern = %d{ABSOLUTE} % 5 p %c{ 1 }:%L - %m%n log4j.appender.E = org.apache.log4j.DailyRollingFileAppender log4j.appender.E.File = logs/log_error.log log4j.appender.E.Append = true log4j.appender.E.Threshold = ERROR log4j.appender.E.layout = org.apache.log4j.PatternLayout log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n Conditional Log In some cases, we want to log some specifi...

RabbitMQ Learning (2): Application

In the last blog , we have skim the basic concept and abstraction in RabbitMQ. Today, we apply message communication into our specific problem to solve it. Timer Background We would like to build a separated timer process to manage many timing jobs, which can schedule a job at specific time, run regularly. In order to decrease degree of coupling, we have already make it a single process. So we have to use inter-process communication to interact with it. We choose the message queue to finish the job rather than RPC, because we don’t have a very demanding requirement of performance and we can make our system even more loosely coupled. When choosing message middleware, we take reliability and performance into account, compare the RabbitMQ and Kafka. Because we prefer reliability than performance, we choose RabbitMQ. Design Choice In next step, we have to make some decision about RabbitMQ: Exchange type: In last blog of RabbitMQ basic concept, we have introduce there...