Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6533073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:04:51+00:00 2026-05-25T10:04:51+00:00

My Java-program does a multithreaded XSLT Transformation and writes the results to a file.

  • 0

My Java-program does a multithreaded XSLT Transformation and writes the results to a file. To avoid the IO bottleneck I am experimenting with the new AsynchronousFileChannel.
The XSLT-Threads should submit their output as strings (which works) and the Writer to append them to the file (that does not work yet).

I wrote a custom Writer-class for the write-operations. My Threads call the Writer.write(String text)-method. In there I would like to append the String as ByteBuffer to the AsynchronousFileChannel.
Unfortunately, I could find no hint what to use as the position value in asyncOutput.write(ByteBuffer, Long). I tried different values for position without success (Output gets scrambled). I am pretty sure, there is no problem with synchronization as the code works well with FileChannels (which do not support a simple non blocking io mode):

  • asyncOutput.size()
  • asyncOutput.size() + future.get().longValue()
  • 0

Here’s the code how I am trying to do this:

public class MyWriter {
private AsynchronousFileChannel asyncOutput;    

    MyWriter(String filename) throws IOException {
        asyncOutput = AsynchronousFileChannel.open(Paths.get(filename), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
    }

    public void write(String output) throws IOException, ExecutionException, InterruptedException {
        System.err.println("Write was called");
        this.future = asyncOutput.write(string2ByteBuffer(output), asyncOutput.size());
    }

    public ByteBuffer string2ByteBuffer (String text){
    ...
    }
}

The method is called from a the XSLT-Threads (Runnable) like this:

synchronized (this) {
        this.write2Writer(outputXmlWriter.toString());
        }
...
private void write2Writer(String output) throws IOException {
    try {
        myWriter.write(output);
    } catch (ExecutionException | InterruptedException ex) {
        ex.printStackTrace();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:04:51+00:00Added an answer on May 25, 2026 at 10:04 am

    The solution extracted from the link:

    Future<Integer> future = asyncOutput.write(string2ByteBuffer(output), this.position);
    this.position += future.get();
    

    Source: http://cr.openjdk.java.net/~alanb/6830721/webrev.00/test/java/nio/channels/AsynchronousFileChannel/Basic.java.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My java program writes information on PDF form. Does anyone know a good way
I have a java program which does individual jobs e.g. takes in a file,
Why does this test program result in a java.lang.IllegalMonitorStateException ? public class test {
Is there any functionality in Java for pausing the program like system(PAUSE); does in
I am writing a java program that needs a file open dialog. The file
I am interested in writing a Java program which does the following. Attach to
I have a simple Java program which reads a file directory and outputs a
I've been asked (as part of homework) to design a Java program that does
I have a Java program that does some String matching. I'm looking for anything
I have a problem.... I made a java program that does the following: BufferedReader

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.