Gadtry是一个java工具库集合。包含:ioc, exec(fork进程),graph(图计算)等等常用工具集,并且完全零依赖。
Usemave
<depedecy> <groupId>com.github.harbby</groupId> <artifactId>gadtry</artifactId> <versio>1.1.0</versio></depedecy>gradle
compile group: 'com.github.harbby', ame: 'gadtry', versio: '1.0.0'IocCreateFactory:
IocFactory iocFactory = IocFactory.create(bider -> { bider.bid(Set.class).by(HashSet.class).withSigle(); bider.bid(HashSet.class).withSigle(); bider.bid(List.class).byCreator(ArrayList::ew); //Sigle object bider.bid(Object.class, ew Object()); bider.bid(Map.class).byCreator(HashMap::ew).withSigle(); //Sigle object bider.bid(TestIject.class);});Set a1 = iocFactory.getIstace(Set.class);Set a2 = iocFactory.getIstace(Set.class);Assert.assertEquals(true, a1 == a2); // Sigle objectClassIject
public class TestIject{ @Autowired private TestIject test; @Autowired public TestIject(HashMap set){ System.out.pritl(set); }}ExecNewJvmThrowthetasktothechildprocess
JVMLaucher laucher = JVMLauchers.ewJvm() .setCallable(() -> { // this is child process System.out.pritl("************ ruig your task ***************"); retur 1; }) .addUserjars(Collectios.emptyList()) .setXms("16m") .setXmx("16m") .setCosole((msg) -> System.out.pritl(msg)) .build();VmFuture out = laucher.startAdGet();Assert.assertEquals(out.get().get().itValue(), 1);






评论