This Java application launches an HTTP server that processes requests to count the occurrences of a word in the text of "War and Peace". It's a multi-threaded server that can handle multiple requests simultaneously.
- HTTP server listening on port 8000.
- Multi-threaded processing with a pool of 8 threads.
- Word counting in the entire text of "War and Peace".
- Input is provided via HTTP GET requests.
- Java Development Kit (JDK) must be installed to compile and run the application.
- The text file "war_and_peace.txt" must be located in the
./resources/
directory relative to the application's executable.
- Clone the repository or download the source code.
- Ensure "war_and_peace.txt" is placed in the
./resources/
directory. - Compile the code using a Java compiler. For example:
javac ThroughputHttpServer.java
- Start the server by running the compiled Java class. For example:
java ThroughputHttpServer
- The server will start listening for connections on
http://localhost:8000
. - To count occurrences of a word in the text, make a GET request to
http://localhost:8000/search?word=your_word_here
. Replaceyour_word_here
with the word you want to count. - The server will respond with the count of the word's occurrences in the text.
To count how many times the word "war" appears in the text, navigate to:
http://localhost:8000/search?word=war
The server will respond with the number representing the count of "war" in the text.
ThroughputHttpServer.java
: The main server class that sets up the HTTP server and handlers.WordCountHandler
: An inner class implementingHttpHandler
to process word count requests.
The server accepts a single query parameter word
which is the word to be counted in the text.
- URL:
/search
- Method:
GET
- URL Params:
word=[string]
For a request to http://localhost:8000/search?word=peace
, the server might respond with:
1024
indicating that the word "peace" appears 1024 times in the text.
If the server doesn't start, ensure that port 8000 is free and not being used by another service.