I want to fetch some data from service by callable and future. This is one of my code:
@Override
public void getCIFilesType(Consumer<String> consumer) {
try {
consumer.accept(serviceExecutor.submit(() ->
service.getCi(EsupFactory.getConfigString(SETTING_ROOT_CI) + "GetCI",
translator.makeCiJsonObject("PCiName", "CI_FilesType")).execute())
.get().body().string());
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
I have 10 method like this that execute like above.I used Executor service to run callable
:
ExecutorService serviceExecutor = Executors.newSingleThreadExecutor();
I'm my activity I have a menu and then click on one item in the menu a fragment is a transaction in activity. All of the thread tasks immediately started in onViewCreated
in fragment:
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
presenter.getCis();
}
But when I clicked on the menu item UI
is frizzed till all task down then transaction is down. This is not the first time that I have this problem. Every time I use callable and executor service I do not know why UI is frizzed!!!!
This is profiler :
Someone has some guidance for me!!? Please do not tell me to use asyncTask :-)
What is a read line?? In ui thread I just do transaction not execute long running task!!!