Asynchronous web programming using Java

Click For Summary

Discussion Overview

The discussion revolves around asynchronous web programming using Java, specifically in the context of using Eclipse and Tomcat. Participants explore whether these tools support asynchronous programming and server push technologies, and they discuss various libraries and implementations available for Java.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant inquires about the support for asynchronous programming and server push technologies in Eclipse and Tomcat.
  • Another participant suggests NodeJS as a popular alternative for asynchronous web programming, highlighting its scalability and reliance on JavaScript.
  • A participant expresses a desire to learn Java web programming and seeks confirmation of asynchronous programming implementations available for Java.
  • There is a clarification regarding server push, describing a mechanism where the client sends requests and the server responds, allowing for updates.
  • Some participants mention the existence of a simple asynchronous API in Java, specifically AsynchronousSocketChannel and AsynchronousServerSocketChannel, which could be sufficient for implementing server push.
  • One participant shares code from a Netty example but encounters a 404 error when running it with Tomcat, indicating a possible configuration issue.
  • Another participant reports successfully running the Netty example directly with Java, suggesting that the issue lies in the Tomcat configuration rather than the code itself.
  • There are mentions of alternative libraries to Netty, indicating that participants are considering various options for asynchronous programming in Java.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best tools or methods for asynchronous programming in Java, as multiple competing views and suggestions are presented throughout the discussion.

Contextual Notes

There are unresolved issues regarding the configuration of Tomcat and the specific implementation details of the shared code. The discussion also reflects varying levels of familiarity with different libraries and tools.

Who May Find This Useful

Individuals interested in asynchronous web programming with Java, particularly those using Eclipse and Tomcat, as well as those exploring alternatives like Netty or NodeJS.

ShayanJ
Science Advisor
Insights Author
Messages
2,802
Reaction score
605
I want to learn web programming with Java. I'm using eclipse neon with tomcat 8.5.13. My question is do these tools support asynchronous programming and server push technologies or should I use other tools?
Thanks
 
Technology news on Phys.org
NodeJS is a popular alternative to Tomcat and Java. Everything client and server side is done in javascript. Its asynchronous and scalable. Many sites rely on NodeJS too.
 
I know about NodeJS but I want to learn Java web programming. I'm sure there is an implementation of asynchronous web programming for Java too, isn't there?
 
Ahh okay.

So when you say server push, you really mean the client sends a request and once the server responds the client immediately sends another request for update. This allows the server to respond whenever and it has a port to do it.

https://en.wikipedia.org/wiki/Push_technology
 
There is a simple async API built into Java in the form of AsynchronousSocketChannel and AsynchronousServerSocketChannel. Those are already sufficient to implement server push. But there are also more full featured libraries like e.g. Netty.
 
DrZoidberg said:
There is a simple async API built into Java in the form of AsynchronousSocketChannel and AsynchronousServerSocketChannel. Those are already sufficient to implement server push. But there are also more full featured libraries like e.g. Netty.
I downloaded Netty and tried to run an example. So I created a project with the code below(got it from here):
Java:
//package io.netty.example.discard;

import io.netty.buffer.ByteBuf;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
* Handles a server-side channel.
*/
public class DiscardServerHandler extends ChannelInboundHandlerAdapter { // (1)

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) { // (2)
        // Discard the received data silently.
        ((ByteBuf) msg).release(); // (3)
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { // (4)
        // Close the connection when an exception is raised.
        cause.printStackTrace();
        ctx.close();
    }
}

But when I run it with tomcat, I get:
HTTP Status 404 – Not Found
Type Status Report

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.13

P.S.
I commented package io.netty.example.discard; because it gives the error:
The declared package "io.netty.example.discard" does not match the expected package ""
 
I don't have a tomcat installation. But I did run the example code on http://netty.io/wiki/user-guide-for-4.x.html directly with
java -cp .;"E:\netty-4.1.9.Final\jar\all-in-one\netty-all-4.1.9.Final.jar" io.netty.example.discard.DiscardServer
and it worked fine. There must be some error in your tomcat configuration.
Btw. There are many libraries you could use. It doesn't have to be netty. A quick google search for "netty alternatives" will give you several other options. You could even just use the built in classes if your task is relatively simple.
 

Similar threads

Replies
86
Views
3K
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 43 ·
2
Replies
43
Views
7K
  • · Replies 15 ·
Replies
15
Views
3K
Replies
3
Views
4K