Month: June 2018

A linux function to make current java code directory into a tarball without including unwanted files

Put the following function into your ~/.bashrc, and run “tarcode” in your code directory. It will generate a *.tgz file under ~/temp tarcode() { filename=`basename “$PWD”` filename+=’-‘ filename+=`date ‘+%Y-%m-%dT%H%M%S’` filename=$HOME’/temp/’$filename’.tgz’ echo $filename tar –exclude=’.git’ –exclude=’.DS_Store’ –exclude=’.classpath’ –exclude=’.gitignore’ –exclude=’.project’ –exclude=’.settings’ –exclude=’target’ -zcvf $filename . }

Dynamic file name in log4j’s file appender

In your log4j.xml, set the file name as a variable <appender name=”my-file-appender” class=”org.apache.log4j.FileAppender”> <param name=”file” value=”${myFilePath}” /> <!– … –> </appender> Then in your java code, make sure the following is called before the first getLogger() call System.setProperty(“myFilePath”, someFilePath);

Quick log4j set up

<!– pom.xml –> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.7</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.7</version> </dependency> <!– src/main/resources/log4j.xml –> <?xml version=”1.0″ encoding=”UTF-8″?> <!DOCTYPE log4j:configuration SYSTEM “log4j.dtd”> <log4j:configuration xmlns:log4j=”http://jakarta.apache.org/log4j/”> <appender name=”my-file-appender” class=”org.apache.log4j.FileAppender”> <param name=”file” value=”some.file” /> <param name=”append” value=”true” /> <param name=”encoding” value=”UTF-8″ /> <layout class=”org.apache.log4j.PatternLayout”> <param name=”ConversionPattern” value=”%d %t %-5p %c – %m%n” /> </layout> </appender> <appender name=”console” …

Quick log4j set up Read More »

Basic Redux Counter example

In this example, The "CounterComponet" is included by the root component called "AppComponent". No Store composition is used here. You still have to pass the props to "AppComponent", which in turn passes them to "CounterComponent" So it will not demonstrate how good Redux is, but will just let you know the basic ideas of Redux. …

Basic Redux Counter example Read More »

Frontend frameworks and things you should know in addition to React/Angular

Language ES2015: A new generation of Javascript language specs. It supports modules and classes. It’s also know as ES6 Typescript: An object-oriented language that will be converted to Javascript and then be run in browsers Babel: make code run in an browser that doesn’t support this code, for example running ES6+ in current browsers, or …

Frontend frameworks and things you should know in addition to React/Angular Read More »

How to prevent Quartz from re-firing a job while it is still running

Answer: use @DisallowConcurrentExecution Example Without this annotation import java.time.LocalTime; import org.quartz.DisallowConcurrentExecution; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; public class HelloJob implements Job { @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { System.out.println(Thread.currentThread().getName() + “:Job started at ” + LocalTime.now()); try { Thread.sleep(10 * 1000); } catch (InterruptedException e) { throw new RuntimeException(e); } System.out.println(Thread.currentThread().getName() + …

How to prevent Quartz from re-firing a job while it is still running Read More »

Quartz concepts

Basic concepts Job: What to do Trigger: When to do it Scheduler: The director to associate triggers to jobs and to invoke the trigger A job can be associated with several triggers, but a trigger should not be used to trigger more than one job Go into details for some depth JobKey = Job Name …

Quartz concepts Read More »