Skip to content

Instantly share code, notes, and snippets.

package test.another;
import java.util.concurrent.CountDownLatch;
public class TestThread extends Thread{
public static void main(String[] args) {
CountDownLatch latch = new CountDownLatch(2);
new Thread(new TestRunnable(latch, "1")).start();
new Thread(new TestRunnable(latch, "2")).start();
@cassc
cassc / TestThreadJoin.java
Created April 5, 2014 15:40
Demonstrate usage of java Thread.join() method
package test.another;
import java.util.concurrent.TimeUnit;
public class TestThreadJoin {
public static void main(String[] args) throws InterruptedException {
Thread t1 = new JoinedThread("1");
t1.start();
// Thread 2 waits for thread 1 to end
@cassc
cassc / TestInterrupt.java
Created April 8, 2014 01:54
Java interrupt medthod
/*
* Demonstrate thread.interrupt() method;
*/
package test.another;
import java.util.concurrent.TimeUnit;
public class TestInterrupt {
public static void main(String[] args) {
Thread t1,t2;
@cassc
cassc / TestSemaphore.java
Created April 8, 2014 05:50
Semaphore exmaple from TIJ
/*
* Semaphore example
*/
package test.another;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
@cassc
cassc / TestAnnotation.java
Created April 9, 2014 08:16
Java Annotation basics
/*
* Basic usage of Java annotation
*/
package test.another;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@cassc
cassc / CookieHttpRequestTest.java
Created April 17, 2014 04:30
Use shared HttpClient instance for multiple requests
package concurrentRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.http.HttpEntity;
@RequestMapping(value="/pushMsg")
public void pushMsg(HttpServletRequest request, HttpServletResponse response){
long t0 = System.currentTimeMillis();
log.info("Starting ");
Continuation continuation = ContinuationSupport.getContinuation(request);
continuation.setTimeout(5000);
continuation.suspend();
long t1 = System.currentTimeMillis();
log.info("Suspended ");
Integer count=(Integer) continuation.getAttribute("count");
@cassc
cassc / pdf-trim.tex
Last active October 17, 2020 10:56
Trim/Crop PDF file with LaTeX
\documentclass[12pt,oneside,a4]{article}
\usepackage{forloop}
\usepackage{ifthen}
\usepackage{graphicx}
\usepackage{pdfpages}
\setlength{\parindent}{0pt}
@cassc
cassc / specter.example.clj
Created November 22, 2017 10:08
com.rpl.specter-example
(use 'com.rpl.specter)
;; 过滤元素
(filter odd? [1 2 3 4 5 6]) ;; (1 3 5)
(select [ALL odd?] [1 2 3 4 5 6]) ;; [1 3 5]
;; 选择奇数位的元素
(select [INDEXED-VALS (comp odd? first) LAST] [:a :b :c :d :e]) ;; [:b :d]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@cassc
cassc / clojure-java-getter.clj
Created February 16, 2019 03:25
Call java no-arg getter in clojure
(defn invoke-get [obj ^String field]
(.. obj
(getClass)
(getDeclaredMethod (str "get" (clojure.string/capitalize field)) (into-array Class nil))
(invoke obj (into-array Class nil))))
(invoke-get (java.util.Date.) "time")