Amazon EC2 stops working unexpectedly - java

I am facing a problem that is burning my brain. I have an amazon ec2 instance that runs Linux AMI, I installed tomcat7 and I am deploying my webservice in it. This webservice connects itself with an amazon RDS instance where I have my mysql (that I use to validate user and password). When I start my tomcat7 service everything works great, after one hour I can't log in into my system.
If i restart the tomcat7 service, everything works again. But why?
I really don't know where is the problem. I can connect to my database directly from my project in eclipse, and via command line.
I don't know why if I restart the service, my webservice works again. I know that the service hasn't stoped, because I can access the login page of my webapp.
I really appreciate any kind of help,
Rodrigo Araujo.
ps: Last week, everything was working just fine.

I've seen such behavior before, it is probably tomcat and not ec2. Check the following:
1- Your threading configuration (maxThreads and acceptCount). I've seen this behavior using the blocking connector when currentThreadsBusy > maxThreads. Check that you have enough threads or use the non-blocking (nio) connector.
2- Check that your connection pool can reconnect lost connections automatically (autoReconnect=true in the jdbc url), your threads might be waiting db io on lost connections.
Anyway, your ec2 instance is probably still working...

Related

Multiple spring boot instances on different ports - login/logout problem

I'm setting up a new dev environment on a windows 10 pro installation. Therefore i am exporting my spring-boot applications as .jar file and start it as windows service on different ports.
Spring boot app 1 on port 10001
Spring boot app 2 on port 10002
and so on
I already unlocked those ports in my firewall and everything seems working perfectly fine.
When I log into the application with port 10001, everything seems fine as well. However as soon as i log into another application (10002) i get automatically logged off on the 10001 application.
To sum it up, I am only able to be logged into one application at a time.
I am using a MySql8 Server installation. All applications have their own databaseschema. Additionally i am using spring security for authentication.
Because all those applications are running perfectly fine on our productive server (jelastic web hosting) it should have something to do with my dev environment instead of a code issue.
I'm happy you solved your problem. I don't think that using SSL and subdomains is the most simplistic solution to your problem though, especially if you are running automated tests in that environment, ssl might slow you down a bit.
There is a well known address you can bind your application to: 127.0.0.1. However, most people don't know, that your loop back device is actually listening to 127.0.0.1/8 in other numbers 127.0.0.1 with a netmask of 255.0.0.0 which means you can bind your services to any address in a whole class a subnet.
TLDR: try binding your application 1 to 127.0.0.2 and application 2 to 127.0.0.3. That should help with the cookies and later on, if you add monitoring ports, will make your life of managing port numbers easier.
As already mentioned in my comment above, the problem is not related to any software bug, instead its just how http is defined:
"Cookies do not provide isolation by port. If a cookie is readable by a service running on one port, the cookie is also readable by a service running on another port of the same server."
Are HTTP cookies port specific?
I solved my issue by using SSL encryption and different subdomains.

How to make a local test server for an android app?

I basically need to create a test server, something that I can use locally to perform tasks for my application.
So my android app is basically a search engine, however the search queries will be made on the server and the results then fetched from the server on the mobile device as JSON objects.
Is there any way to replicate this functionality locally? I would just like to set up a server, include the Spring framework, the Google Custom Search API and develop it all in Java, then ship it to a live server directly when it's finished. (Most presumably a free tier Amazon AWS server, either EC2 or Lambda, not sure what the difference is).
Not quite sure where or how to get started so any help is appreciated, thank you!
p.s. I may try dabbling in some machine learning at a later date, but I don't know if this will affect anything, this will most likely be after I've got a live server up and running.
EDIT: Sorry, so how would I fetch data from a local server from my mobile device? Do I need special software? Do I need to configure a local server? How can my mobile device fetch data from a second project when its being run on the first?
My app will fetch data from a server, so how can I create a dummy server, for it to fetch data from? Will I need to create a fully functioning online server, or can this just be done through creating a local server of some sort and then simply plugging my android device in and running the code? I have absolutely no idea how to test it without putting it online.
You can run a local installation of Tomcat server on your own machine.
Access the server by visiting "http://localhost:8080/" (or) http://127.0.0.1:8080". You can basically listening to your own local machine / host's 8080 port. Sometimes, it could be port 80 instead of 8080.
Please explore on how to host a Spring or Java application on a local server.
A good starting point would be to learn J2EE or Enterprise Java. You can configure Databases from your local installation.
If you opt for PHP as your language on server side, there is a pre-defined package called WAMP (for Windows), LAMP (for Linux), MAMP (for MAC) and XAMPP.
The above package are nothing but a package which contains a Server, Database and a Server side language usually PHP, if needed Python or Perl.
Please explain in which step you are getting issues so that anyone can help you exactly.

How to host a java application (without using webservices)

I made a game with sockets that works fine on my machine, and now I would like to run the server on a host so that anyone can join in at any time.
All I'm finding are services for web applications, mine is just a swing application that can run by itself.
What kind of server can I use (instead of my own machine)? Would I need to change the code or is it possible to just find a host that runs my server application as is?
Also, note that for now I kept it simple, there is no data storage.
Take a look at Amazon EC2 cloud. Essentially what you're looking to do is acquire a public IP address (an be done from the Amazon EC2 admin console). You'll be installing java and then opening a port in your security settings to allow traffic to whatever port your game server is running on.
EC2 is free for low volumes of usage for the first year (new accounts only) and I've had fairly good luck with them in terms of downtime and affordability.

XAMPP / java.net.BindException: Address already in use

I was wondering if someone could help me out with an issue I'm having. I'm using a Jetty server and using XAMPP to connect to a MySQL server, which I'm accessing through PHPMyAdmin.
I have a class that essentially is meant to drop all the tables in a database and then add some more, with data.
The first time I ran it, it worked fine, and did what it's meant to do, but the next time, I'm getting errors like the ones below. If I try it with a different database on the same host, again, it works fine first time, but any additional attempts will not work.
Can anyone shed some light please?
It seems that your Jetty instance is already running. Try to stop it and then run your test again.
If I try it with a different database on the same host, again, it works fine first time, but any additional attempts will not work.
This is happening because, I suppose, you are trying to start the server every time you start a test, but not closing after the test is done.
You can now either stop your Jetty instance manually, using Task Manager, restarting your machine in order to be able to run tests again
You've probably ran Jetty server twice or port 8444 is being 'listened' by another application.
Fire that command and find out which service is using that port
netstat -aon | find /i "listening"

Server app hosted on VPS hangs up

I'm developing a simple server-client app. Server application is hosted on a VPS. I have a problem with it: it behaves weirdly... When I test it on my PC it works fine, but when I launch it on VPS it (program) hangs up when a client app try to connect (the protocol is TCP). I can't even kill it with "killall -vs TERM java" command, so I need to reboot a whole VPS in order to restart it. Client and server apps are both written on Java. The VPS OS is Ubuntu. Can anyone give me a piece of advice of that matter please?
Actually, the problem was in the System.out.println("some_text") commands. My server didn't want to work without this commands in certain places. Why - I don't know yet. I'll do some researches conducted with that behaviour. But anyway, that's a subject for another question.

Categories

Resources