This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Utils { | |
private Utils() { | |
} | |
public static void echo(String msg) { | |
System.out.println(msg); | |
} | |
public static void sleep(int millis) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers | |
-------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns | |
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms | |
Read 4K randomly from SSD* 150,000 ns 0.15 ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ page language="java" contentType="text/html;charset=UTF-8" %> | |
<%@ page import="org.apache.log4j.Level" %> | |
<%@ page import="org.apache.log4j.LogManager" %> | |
<%@ page import="org.apache.log4j.Logger" %> | |
<%@ page import="java.util.HashMap" %> | |
<%@ page import="java.util.Enumeration" %> | |
<%@ page import="java.util.Set" %> | |
<%@ page import="java.util.Arrays" %> | |
<% | |
/* This was originally suggested by Nelz on http://nelz.net/2008/04/08/log4j-runtime-configuration */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean decTillZero(AtomicLong counter) { | |
while (true) { | |
long current = counter.get(); | |
if (current == 0) { | |
return false; | |
} | |
long next = current - 1; | |
if (counter.compareAndSet(current, next)) { | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Atomically adds the given value to the current value. | |
* | |
* @param delta the value to add | |
* @return the previous value | |
*/ | |
public final long getAndAdd(long delta) { | |
while (true) { | |
long current = get(); | |
long next = current + delta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.inlinetelecom.vn2.util; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import java.util.concurrent.atomic.AtomicLong; | |
/** | |
* вариант с uncontended lock (getAvailableProcessors >= worker_count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.inlinetelecom.vn2.util; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import java.util.concurrent.atomic.AtomicLong; | |
/** | |
* вариант с uncontended lock (getAvailableProcessors >= worker_count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru; | |
public interface InterfaceJava8 { | |
public static void main(String[] args) { | |
System.out.println("Hello from interface! It is java 8!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lambda.puzzle; | |
// source: http://arhipov.blogspot.ru/2014/02/java-8-lambdas-unintentional-puzzle.html | |
public class Forrest { | |
public Runnable wrooom(){ | |
return () -> { System.out.println("Hello, lambda!"); }; | |
} | |
public static void main(String[] args) { | |
Runnable runnable = new Forrest().wrooom(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru; | |
// origin source: http://arhipov.blogspot.ru/2014/02/java-8-lambdas-unintentional-puzzle.html | |
// my gist with puzzle https://gist.github.com/iaveryanov/10990181 | |
public class Forrest { | |
public Runnable wrooom(){ | |
return new Runnable() { | |
@Override | |
public void run() { | |
System.out.println("Hello, lambda!"); |
OlderNewer