cannot invoke stream() on the primitive type void while doing —...











up vote
-1
down vote

favorite












I was trying to implement a java program to read a huge file simultaneously by 100 threads.
So I am dividing my file in 100 chunks and giving it to 100 threads.
And at the end I want to calculate the capacity of each chunk and and print the total capacity read by all threads.



Below is my code...
And I am getting errors in my code and I am not able to fix it. I am new to concurrency and Multithreading .Please help me to understand and fix this issue.



public class CustomRecursiveTaskToReadHugeFile extends RecursiveTask {
static volatile boolean flag;
File file;
FileChannel fc;
BlockingQueue<Integer> bq;
public CustomRecursiveTaskToReadHugeFile(boolean flag, File file, FileChannel c) {
super();
this.flag = flag;
this.file = file;
this.fc = c;
}

@Override
protected Integer compute() {
if (!flag) {
return ForkJoinTask.invokeAll(createSubtasks()).stream().mapToInt(ForkJoinTask::join).sum(); // Here is the problem area
} else
processFiles();
}

private Collection<CustomRecursiveTaskToReadHugeFile> createSubtasks() {
List<CustomRecursiveTaskToReadHugeFile> cl = new ArrayList<CustomRecursiveTaskToReadHugeFile>();

if (!flag) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
FileChannel c = is.getChannel();
for (long i = 0; i < 1000000; i = i + 100) {
try {
c.position(i);
cl.add(new CustomRecursiveTaskToReadHugeFile(flag, file, c));
} catch (IOException e) {
e.printStackTrace();
}
}
}
return cl;
}

private Integer processFiles() {
ByteBuffer dst = null;
for (int i = 0; i < 00; i++) {
try {
fc.read(dst, i);

} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(" Current thread capacity is " + dst.capacity());
try {
bq.put( new Integer(dst.capacity()));
} catch (InterruptedException e) {
e.printStackTrace();
}

return new Integer(dst.capacity());

}
}









share|improve this question




















  • 1




    invokeAll return type is void. You can't call a method (.stream() in your case) on void.
    – Kartik
    yesterday










  • hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
    – Rama Tripathi
    19 hours ago















up vote
-1
down vote

favorite












I was trying to implement a java program to read a huge file simultaneously by 100 threads.
So I am dividing my file in 100 chunks and giving it to 100 threads.
And at the end I want to calculate the capacity of each chunk and and print the total capacity read by all threads.



Below is my code...
And I am getting errors in my code and I am not able to fix it. I am new to concurrency and Multithreading .Please help me to understand and fix this issue.



public class CustomRecursiveTaskToReadHugeFile extends RecursiveTask {
static volatile boolean flag;
File file;
FileChannel fc;
BlockingQueue<Integer> bq;
public CustomRecursiveTaskToReadHugeFile(boolean flag, File file, FileChannel c) {
super();
this.flag = flag;
this.file = file;
this.fc = c;
}

@Override
protected Integer compute() {
if (!flag) {
return ForkJoinTask.invokeAll(createSubtasks()).stream().mapToInt(ForkJoinTask::join).sum(); // Here is the problem area
} else
processFiles();
}

private Collection<CustomRecursiveTaskToReadHugeFile> createSubtasks() {
List<CustomRecursiveTaskToReadHugeFile> cl = new ArrayList<CustomRecursiveTaskToReadHugeFile>();

if (!flag) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
FileChannel c = is.getChannel();
for (long i = 0; i < 1000000; i = i + 100) {
try {
c.position(i);
cl.add(new CustomRecursiveTaskToReadHugeFile(flag, file, c));
} catch (IOException e) {
e.printStackTrace();
}
}
}
return cl;
}

private Integer processFiles() {
ByteBuffer dst = null;
for (int i = 0; i < 00; i++) {
try {
fc.read(dst, i);

} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(" Current thread capacity is " + dst.capacity());
try {
bq.put( new Integer(dst.capacity()));
} catch (InterruptedException e) {
e.printStackTrace();
}

return new Integer(dst.capacity());

}
}









share|improve this question




















  • 1




    invokeAll return type is void. You can't call a method (.stream() in your case) on void.
    – Kartik
    yesterday










  • hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
    – Rama Tripathi
    19 hours ago













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I was trying to implement a java program to read a huge file simultaneously by 100 threads.
So I am dividing my file in 100 chunks and giving it to 100 threads.
And at the end I want to calculate the capacity of each chunk and and print the total capacity read by all threads.



Below is my code...
And I am getting errors in my code and I am not able to fix it. I am new to concurrency and Multithreading .Please help me to understand and fix this issue.



public class CustomRecursiveTaskToReadHugeFile extends RecursiveTask {
static volatile boolean flag;
File file;
FileChannel fc;
BlockingQueue<Integer> bq;
public CustomRecursiveTaskToReadHugeFile(boolean flag, File file, FileChannel c) {
super();
this.flag = flag;
this.file = file;
this.fc = c;
}

@Override
protected Integer compute() {
if (!flag) {
return ForkJoinTask.invokeAll(createSubtasks()).stream().mapToInt(ForkJoinTask::join).sum(); // Here is the problem area
} else
processFiles();
}

private Collection<CustomRecursiveTaskToReadHugeFile> createSubtasks() {
List<CustomRecursiveTaskToReadHugeFile> cl = new ArrayList<CustomRecursiveTaskToReadHugeFile>();

if (!flag) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
FileChannel c = is.getChannel();
for (long i = 0; i < 1000000; i = i + 100) {
try {
c.position(i);
cl.add(new CustomRecursiveTaskToReadHugeFile(flag, file, c));
} catch (IOException e) {
e.printStackTrace();
}
}
}
return cl;
}

private Integer processFiles() {
ByteBuffer dst = null;
for (int i = 0; i < 00; i++) {
try {
fc.read(dst, i);

} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(" Current thread capacity is " + dst.capacity());
try {
bq.put( new Integer(dst.capacity()));
} catch (InterruptedException e) {
e.printStackTrace();
}

return new Integer(dst.capacity());

}
}









share|improve this question















I was trying to implement a java program to read a huge file simultaneously by 100 threads.
So I am dividing my file in 100 chunks and giving it to 100 threads.
And at the end I want to calculate the capacity of each chunk and and print the total capacity read by all threads.



Below is my code...
And I am getting errors in my code and I am not able to fix it. I am new to concurrency and Multithreading .Please help me to understand and fix this issue.



public class CustomRecursiveTaskToReadHugeFile extends RecursiveTask {
static volatile boolean flag;
File file;
FileChannel fc;
BlockingQueue<Integer> bq;
public CustomRecursiveTaskToReadHugeFile(boolean flag, File file, FileChannel c) {
super();
this.flag = flag;
this.file = file;
this.fc = c;
}

@Override
protected Integer compute() {
if (!flag) {
return ForkJoinTask.invokeAll(createSubtasks()).stream().mapToInt(ForkJoinTask::join).sum(); // Here is the problem area
} else
processFiles();
}

private Collection<CustomRecursiveTaskToReadHugeFile> createSubtasks() {
List<CustomRecursiveTaskToReadHugeFile> cl = new ArrayList<CustomRecursiveTaskToReadHugeFile>();

if (!flag) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
FileChannel c = is.getChannel();
for (long i = 0; i < 1000000; i = i + 100) {
try {
c.position(i);
cl.add(new CustomRecursiveTaskToReadHugeFile(flag, file, c));
} catch (IOException e) {
e.printStackTrace();
}
}
}
return cl;
}

private Integer processFiles() {
ByteBuffer dst = null;
for (int i = 0; i < 00; i++) {
try {
fc.read(dst, i);

} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(" Current thread capacity is " + dst.capacity());
try {
bq.put( new Integer(dst.capacity()));
} catch (InterruptedException e) {
e.printStackTrace();
}

return new Integer(dst.capacity());

}
}






java multithreading concurrency fork-join






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 19 hours ago

























asked yesterday









Rama Tripathi

419




419








  • 1




    invokeAll return type is void. You can't call a method (.stream() in your case) on void.
    – Kartik
    yesterday










  • hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
    – Rama Tripathi
    19 hours ago














  • 1




    invokeAll return type is void. You can't call a method (.stream() in your case) on void.
    – Kartik
    yesterday










  • hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
    – Rama Tripathi
    19 hours ago








1




1




invokeAll return type is void. You can't call a method (.stream() in your case) on void.
– Kartik
yesterday




invokeAll return type is void. You can't call a method (.stream() in your case) on void.
– Kartik
yesterday












hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
– Rama Tripathi
19 hours ago




hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
– Rama Tripathi
19 hours ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404606%2fcannot-invoke-stream-on-the-primitive-type-void-while-doing-forkjointask-i%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404606%2fcannot-invoke-stream-on-the-primitive-type-void-while-doing-forkjointask-i%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)