Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.concurrent.ConcurrentException;
import org.apache.commons.lang3.concurrent.BackgroundInitializer;

public class BuilderMethods {

Expand Down Expand Up @@ -56,5 +58,36 @@ public static void main(final String[] arguments) {
System.out.println(simple1.getName());
System.out.println(simple1.hashCode());
System.out.println(simple1.toString());

SampleLazyInitializer sampleLazyInitializer = new SampleLazyInitializer();

try {
sampleLazyInitializer.get();
} catch (ConcurrentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

SampleBackgroundInitializer sampleBackgroundInitializer = new SampleBackgroundInitializer();
sampleBackgroundInitializer.start();

// Proceed with other tasks instead of waiting for the SampleBackgroundInitializer task to finish.

try {
Object result = sampleBackgroundInitializer.get();
} catch (ConcurrentException e) {
e.printStackTrace();
}
}
}

class SampleBackgroundInitializer extends BackgroundInitializer<String>{

@Override
protected String initialize() throws Exception {
return null;
}

// Any complex task that takes some time

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand All @@ -20,6 +22,7 @@
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.arch.Processor;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.apache.commons.lang3.concurrent.ConcurrentException;
import org.apache.commons.lang3.concurrent.ConcurrentRuntimeException;
import org.apache.commons.lang3.concurrent.ConcurrentUtils;
Expand Down Expand Up @@ -133,4 +136,14 @@ public void testLazyInitializer() throws Exception {
assertEquals(sampleObjectOne, sampleObjectTwo);
}

@Test
public void testBuildDefaults() {
BasicThreadFactory.Builder builder = new BasicThreadFactory.Builder();
BasicThreadFactory factory = builder.build();
assertNull("No naming pattern set Yet", factory.getNamingPattern());
BasicThreadFactory factory2 = builder.namingPattern("sampleNamingPattern").daemon(true).priority(Thread.MIN_PRIORITY).build();
assertNotNull("Got a naming pattern", factory2.getNamingPattern());
assertEquals("sampleNamingPattern", factory2.getNamingPattern());

}
}