Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Daniel Guo nkcoder

🎯
Focusing
Block or report user

Report or block nkcoder

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nkcoder
nkcoder / TimingThreadPool.java
Created Feb 5, 2017
extending ThreadPoolExecutor, add timing log
View TimingThreadPool.java
package org.nkcoder.module.javatest.concurrent;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Logger;
/**
* created by daniel at 2/5/17 22:54
*/
public class TimingThreadPool extends ThreadPoolExecutor {
@nkcoder
nkcoder / TimingThreadPool.java
Created Feb 5, 2017
extending ThreadPoolExecutor, add timing log
View TimingThreadPool.java
package org.nkcoder.module.javatest.concurrent;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Logger;
/**
* created by daniel at 2/5/17 22:54
*/
public class TimingThreadPool extends ThreadPoolExecutor {
View CompletableFutureTest.java
package org.nkcoder.module.javatest.concurrent;
import java.util.concurrent.CompletableFuture;
/**
* {@link: http://www.deadcoderising.com/java8-writing-asynchronous-code-with-completablefuture/}
* Created by nkcoder on 12/21/16.
*/
public class CompletableFutureTest {
View CompletionServiceTest.java
package org.nkcoder.module.javatest.concurrent;
import java.util.concurrent.*;
/**
* Created by nkcoder on 12/21/16.
*/
public class CompletionServiceTest {
public static void main(String[] args) {
View SemaphoreTest.java
package org.nkcoder.module.javatest.concurrent;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
/**
* created by daniel at 12/16/16 08:33
*/
public class SemaphoreTest {
View CountDownLatchTest.java
package org.nkcoder.module.javatest.concurrent;
import java.time.Duration;
import java.time.Instant;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
/**
* created by daniel at 12/15/16 21:45
*/
@nkcoder
nkcoder / ChangeLogLevel.java
Created Dec 11, 2016
change log level at runtime (logback and slf4j)
View ChangeLogLevel.java
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
/**
* change log level at runtime
* Created by nkcoder on 10/8/16.
@nkcoder
nkcoder / process_log_files.java
Last active Mar 26, 2016
how to process a large number of small files in limited memory?
View process_log_files.java
import java.io.*;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import java.util.stream.Stream;
/**
@nkcoder
nkcoder / DeadLockDemo.java
Created Mar 14, 2016
java dead lock demo
View DeadLockDemo.java
public class DeadLockDemo {
public static void main(String[] args) {
Object o1 = new Object();
Object o2 = new Object();
Runnable r1 = () -> {
synchronized(o1) {
try {
Thread.sleep(3000);
} catch (Exception e) {
You can’t perform that action at this time.