Hot questions for Using GlassFish in wildfly

Question:

please help make this simple example to deploy on Wildfly (preferred version 10.1.0). Sample code:

import org.glassfish.jersey.server.ChunkedOutput;
import javax.ws.rs.*;
import java.io.*;

@Path("/numbers")
public class NumbersResource {

    @GET
    public ChunkedOutput<String> streamExample(){
        final ChunkedOutput<String> output = new ChunkedOutput<String>(String.class);

        new Thread() {
            @Override
            public void run() {
                try {
                    for (int i = 0; i < 100000 ; i++){
                        output.write(i + " ");
                    }
                } catch (IOException e){
                    e.printStackTrace();
                } finally {
                    try {
                        output.close();
                    } catch (IOException e){
                        e.printStackTrace();
                    }
                }
            }
        }.start();
        return output;
    }

}

(the snippet of code belongs to the author MEMORYNOTFOUND. I had added it here just in case the side is shut down for any reason) I had made it deploy on GlassFish and everything is ok. But now, I need this functionality to be ported on Wildfly. And from the import

import org.glassfish.jersey.server.ChunkedOutput;

It seams that class ChunkedOutput belongs to GlassFish us functionality. In other words, is there something similar us functionality with the import from Wildfly jars or I don't know...?

P.S. Please provide a simple example, among the response. Thanks in advance!


Answer:

Use StreamingOutput instead:

@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/<your-path>")
public Response hello() {
    StreamingOutput stream = new StreamingOutput() {
        @Override
        public void write(OutputStream os) throws IOException, WebApplicationException {
            Writer writer = new BufferedWriter(new OutputStreamWriter(os));

            for (...) {
                writer.write(...);
            }
            writer.flush();
        }
    };
    return Response.ok(stream).build();
}

Question:

I decided to check out Wildfly 8.2.0-Final as an application server instead of Glassfish 4.1 as I've heard good things about its speed.

The first thing I did was to create a normal Java EE web application (ant based for now, but I will look into using maven). Compile-on-save is switched on in NetBeans 8.0.2.

However, to my dismay, if I change static content or change the content of a simple REST service such as:

@GET
@Produces("text/plain")
public String getText() {
    return "Foobar";
}

It takes up to several seconds before the change become visible. I could almost live with this for Java classes, but for static content I'd like immediate feedback as I do a lot of incremental small changes.

This usually takes about 200ms on Glassfish (exactly the same code), so I don't understand it's up to 10x slower on Wildfly?


Answer:

I assume from the description that you're deploying to standalone/deployments. The changes made in that folder are picked up by the deployment scanner which, fortunately, is configurable.

There is a very good description in the documentation, but the important part is that you need to lower the scan interval.

If you've never used the JBoss CLI before, you might be interested to know that there's a GUI mode for it. In the bin directory, call the jboss-cli.sh script with the -c option to connect to your local server and the --gui option to start the gui:

<WFLY_HOME>/bin/jboss-cli.sh -c --gui

As you can see in the image above, you can expand the deployment scanner subsystem, then right click the scan-interval attribute and select "write attribute" to open the dialog below.

Lower the number (500ms = half a second), click OK, and remember to click "Submit" in the top right to actually apply your change.