Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions javapatterns.iml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
Expand All @@ -13,5 +12,4 @@
<orderEntry type="library" name="Maven: com.google.guava:guava:11.0.2" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
</component>
</module>

</module>
30 changes: 15 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>1.6</source>
<aggregate>true</aggregate>
<source>1.8</source>
<!--<aggregate>true</aggregate>-->
<doclet>gr.spinellis.umlgraph.doclet.UmlGraphDoc</doclet>
<docletArtifact>
<groupId>gr.spinellis</groupId>
<artifactId>UmlGraph</artifactId>
<version>4.6</version>
</docletArtifact>
<additionalparam>
-inferrel
-inferdep
-quiet
-constructors
-visibility
-types
-postfixpackage
-nodefontsize 9
-nodefontpackagesize 7
</additionalparam>
<!--<additionalparam>-->
<!-- -inferrel-->
<!-- -inferdep-->
<!-- -quiet-->
<!-- -constructors-->
<!-- -visibility-->
<!-- -types-->
<!-- -postfixpackage-->
<!-- -nodefontsize 9-->
<!-- -nodefontpackagesize 7-->
<!--</additionalparam>-->
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.abqjug.javapatterns.singleton.lazylambda;

import com.google.common.base.Supplier;

/**
* User: Matt Lagrotte (matt@lagrotte.net)
* Date: 2/26/18
* Time: 2:00 PM
*/
public class LazyLambdaSingleton {

private static LazyLambdaSingleton instance = null;

private static Supplier<LazyLambdaSingleton> singletonSupplier = () ->
{
instance = new LazyLambdaSingleton();
singletonSupplier = () -> instance;
return instance;
};

public static LazyLambdaSingleton getInstance() {
return singletonSupplier.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.abqjug.javapatterns.singleton.lazylambda;

/**
* User: Matt Lagrotte (matt@lagrotte.net)
* Date: 2/26/18
* Time: 2:00 PM
*/
public class LazyLambdaSingletonClient {
public static class SingletonRunner implements Runnable {
private LazyLambdaSingleton instance;

public LazyLambdaSingleton getInstance() {
return instance;
}

public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
instance = LazyLambdaSingleton.getInstance();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}


public static void main(String[] args) throws InterruptedException {
SingletonRunner runner1 = new SingletonRunner();
SingletonRunner runner2 = new SingletonRunner();
SingletonRunner runner3 = new SingletonRunner();
SingletonRunner runner4 = new SingletonRunner();

Thread t1 = new Thread(runner1);
Thread t2 = new Thread(runner2);
Thread t3 = new Thread(runner3);
Thread t4 = new Thread(runner4);

t1.start();
t2.start();
t3.start();
t4.start();

t1.join();
t2.join();
t3.join();
t4.join();

assert runner1.getInstance() == runner2.getInstance();
assert runner2.getInstance() == runner3.getInstance();
assert runner3.getInstance() == runner4.getInstance();
assert runner4.getInstance() == runner1.getInstance();
assert runner2.getInstance() == runner4.getInstance();
assert runner3.getInstance() == runner1.getInstance();
}
}