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
import java.awt.Component; | |
import java.awt.Container; | |
import java.awt.GridBagConstraints; | |
import java.awt.GridBagLayout; | |
import java.awt.Insets; | |
import java.util.function.Consumer; | |
/** | |
* This greatly streamlines using the GridBagLayout | |
* Instantiate with the targeted container as an argument through the static factory forContainer() | |
* Then use the "addItem" method to add components. After calling addItem, start chaining the GridBag parameters and then call "finalizeConstraints". |
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
import java.util.function.Supplier; | |
/**<html>A simple but powerful concurrency utility that simplifies lazy initialization. <br><br>Client simply provides a | |
* supplier for the lazy-initialized value to the static factory method <b>forSupplier()</b><br><br> | |
* A LazyObject will be returned by the static factory, and the first time <b>get()</b> is called, the value is initalized and cached in a concurrent/threadsafe manner. | |
* </html> | |
*/ | |
public final class LazyObject<T> { |
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
/**<html>A synchronizer simliar to CountDownLatch, except it is used for situations where the countdown number is not known until later.<br><br> | |
*This makes it ideal for mulitthreading record-buffering tasks, where you want to kick off a concurrent task for each record but do not know how many records there will be</html> | |
*/ | |
public final class BufferedLatch { | |
private int leadCount; | |
private int chaseCount; | |
private boolean leaderComplete = false; | |
public synchronized void incrementLeadCount() { | |
if (leaderComplete) { |
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
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils; | |
import rx.Observable; | |
import rx.functions.FuncN; | |
import rx.subjects.BehaviorSubject; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; |
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
@Test | |
public void hikariTest() { | |
try { | |
HikariConfig config = new HikariConfig(); | |
config.setJdbcUrl("jdbc:sqlite://C:/mydatabases/mydb.db"); | |
config.setUsername("bart"); | |
config.setPassword("51mp50n"); | |
config.setMinimumIdle(1); | |
config.setMaximumPoolSize(5); |
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
import java.util.concurrent.atomic.AtomicBoolean | |
import kotlin.concurrent.thread | |
fun main(args: Array<String>) { | |
val queue = SingleBlockingQueue<Int>() | |
val isDone = AtomicBoolean(false) | |
thread { | |
for (i in 1..100) { |
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
import java.util.concurrent.Semaphore; | |
public final class SingleBlockingQueue<T> { | |
private volatile T value; | |
private final Semaphore full = new Semaphore(0); | |
private final Semaphore empty = new Semaphore(1); | |
private volatile boolean hasValue = false; |
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 class JavaLauncher { | |
public static void main(String[] args) { | |
Observable<Integer> source = Observable.range(1,10); | |
source.map(i -> sleep(i, 250)) | |
.doOnNext(i -> System.out.println("Emitting " + i + " on thread " + Thread.currentThread().getName())) | |
.flatMap(i -> | |
Observable.just(i) | |
.subscribeOn(Schedulers.computation()) | |
.map(i2 -> sleep(i2 * 10, 500)) |
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 org.cakesolutions.spark.kryo | |
import com.esotericsoftware.kryo.Kryo | |
import com.esotericsoftware.kryo.io.Input | |
import com.esotericsoftware.kryo.io.Output | |
import java.io.FileInputStream | |
import java.io.FileOutputStream | |
fun main(args: Array<String>) { | |
val kryo = Kryo() |
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
//compile 'de.javakaffee:kryo-serializers:0.38' | |
class KryoImmutableListTest { | |
class MyItem(val x: Int, val y: Int) { | |
private constructor(): this(-1,-1) | |
override fun toString() = "$x-$y" | |
} | |
@Test |
OlderNewer