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.int_overflow; | |
import org.openjdk.jmh.annotations.*; | |
import org.openjdk.jmh.runner.Runner; | |
import org.openjdk.jmh.runner.RunnerException; | |
import org.openjdk.jmh.runner.options.Options; | |
import org.openjdk.jmh.runner.options.OptionsBuilder; | |
import java.util.concurrent.TimeUnit; |
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.int_overflow; | |
public class IntOverflowPuzzle { | |
// todo почему при использовании long разница в 1000 раз, действительно на столько медленнее | |
// todo почему при переполнении разница во времени в 1000 раз | |
private static void doOperation() { | |
// change type to long | |
// | |
// results: |
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!"); |
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; | |
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 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
/** | |
* 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
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
<%@ 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 */ |
NewerOlder