MyTetra Share
Делитесь знаниями!
ExecutorService
Время создания: 05.12.2019 11:29
Раздел: INFO - Development - CUBA
Запись: wwwlir/Tetra/master/base/1575516591rxg0q76bpr/text.html на raw.githubusercontent.com

import com.groupstp.rtneo.entity.*;

import com.haulmont.cuba.core.global.*;

import com.groupstp.rtneo.service.*;

import com.haulmont.cuba.core.sys.SecurityContext;

import com.haulmont.cuba.core.sys.AppContext;

import java.util.concurrent.ExecutorService

import com.haulmont.cuba.core.sys.SecurityContextAwareRunnable

import java.util.concurrent.Executors


final SecurityContext securityContext = AppContext.getSecurityContext();

//new Runnable() {

// public void run() {

//// AppContext.setSecurityContext(securityContext);

// // business logic here

// System.out.println("!!!!!!!!!!!!")

// log.debug("!!!!!!!!!!!!")

// }

//}


ExecutorService executorService = Executors.newFixedThreadPool(10)

executorService.submit(new SecurityContextAwareRunnable({

try {

System.out.println("!!!!!!!!!!!!S")

log.debug("!!!!!!!!!!!!L")

} catch (Exception e) {

log.error('Error creating entity', e)

}

}))

executorService.shutdown()


==========================================================================


import com.groupstp.rtneo.entity.*;

import com.haulmont.cuba.core.global.*;

import com.groupstp.rtneo.service.*;

import com.haulmont.cuba.core.sys.SecurityContext;

import com.haulmont.cuba.core.sys.AppContext;

import java.util.concurrent.ExecutorService

import com.haulmont.cuba.core.sys.SecurityContextAwareRunnable

import java.util.concurrent.Executors


final SecurityContext securityContext = AppContext.getSecurityContext();

//new Runnable() {

// public void run() {

//// AppContext.setSecurityContext(securityContext);

// // business logic here

// System.out.println("!!!!!!!!!!!!")

// log.debug("!!!!!!!!!!!!")

// }

//}


ExecutorService executorService = Executors.newFixedThreadPool(10)


for(i=0; i<10; i++){

startExec(executorService)

}


//startExec(executorService)

executorService.shutdown()

def startExec(ExecutorService executorService){

executorService.submit(new SecurityContextAwareRunnable({

try {

System.out.println(Thread.currentThread().getName())

log.debug("!!!!!!!!!!!!L")

} catch (Exception e) {

log.error('Error creating entity', e)

}

}))

}


========================================================================================


import com.groupstp.rtneo.entity.*;

import com.haulmont.cuba.core.global.*;

import com.groupstp.rtneo.service.*;

import com.haulmont.cuba.core.sys.SecurityContext;

import com.haulmont.cuba.core.sys.AppContext;

import com.haulmont.cuba.core.sys.SecurityContextAwareRunnable

import java.util.concurrent.*;


final SecurityContext securityContext = AppContext.getSecurityContext();


Runnable task = new Runnable() {

public void run() {

// AppContext.setSecurityContext(securityContext);

System.out.println("MAIN")

System.out.println(Thread.currentThread().getName())

ExecutorService executorService = Executors.newFixedThreadPool(2)

for(def i=0; i<10; i++){

startExec(executorService)

}

executorService.shutdown()

def done = executorService.awaitTermination(1, TimeUnit.MINUTES);

System.out.println(done)

}


}


Thread thread = new Thread(task);

thread.start();



public void startExec(ExecutorService executorService){

Future future = executorService.submit(new SecurityContextAwareRunnable({

try {

System.out.println(Thread.currentThread().getName())

Thread.sleep(1000)

System.out.println("!!!!!!!!!!!!L")

} catch (Exception e) {

log.error('Error creating entity', e)

}

}))

}


 
MyTetra Share v.0.65
Яндекс индекс цитирования