Menu

Port may already be in use

While running any application you may face an issue, that default port or port which our application required to start the process is occupied by some other process or service. In this article we will see how to fix this issue and how we can terminate the active process and service from that port and make it available for our new application. 
below are the steps which we need to follow for windows machine to free the port number.

Error log:

2019-11-22 23:38:18.329 ERROR 27240 --- [  restartedMain] o.apache.catalina.core.StandardService   : Failed to start connector [Connector[HTTP/1.1-8080]]

org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-8080]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:256) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:198) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:300) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) [spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at jobtrees.JobTreesApplication.main(JobTreesApplication.java:25) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_221]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_221]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_221]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_221]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1020) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
... 18 common frames omitted
Caused by: java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_221]
at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_221]
at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_221]
at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) ~[na:1.8.0_221]
at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source) ~[na:1.8.0_221]
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1150) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:591) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1018) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
... 19 common frames omitted

2019-11-22 23:38:18.343  INFO 27240 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-11-22 23:38:18.362  INFO 27240 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-11-22 23:38:18.364 ERROR 27240 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.

How to fix?

To fix this issue and vacant the port you have to kill and stop the current service which is active and running on this port. to do so in your windows machine please follow the following steps.
Step1: Open command prompt(CMD).
Step2: Find the process ID which occupied the port. run the below command to find the PID. to know more on this you may refer our aticle find PID using port number.
netstat -aon | findstr <port number>
let say we want to find the active process ID which is running on port number 4502, hence we will run the below command. 
netstat -aon | findstr 4502
How to find process ID
Find process ID(PID)

Step3: after getting the process ID (PID) you may need to verify which service name or want to know the name of service, then execute the below command.
tasklist /fi "pid eq 8884"
Here, image name is the name of the service. 
How to find the service name using PID
Service name

Step4:
Now we need to stop or kill this active service so we could use another service on same port. To kill a service please run the below command.

taskkill /PID 8884 /F
How to remove an active service from a port.
kill active process/service

We have killed the process and service has been terminated it means now port 4502 is empty and no process or service is currently using that port. We may verify the same by running the command from step2 again.

if you have any query and suggestion, please feel free to pass.


How many hours in a complete day?

Question: Did you know how many hours we have in day? 
or 
Question: How many hours in a complete day? 
or 
Question: How many hours actually in day? 
or 
Question: Are all days exactly 24 hours?
or
Question: How many hours in a day?

Answer: A complete day is twenty three hours, fifty six minutes and four thousand seconds. that is, 23:56:4000 (hh:mm:ss)

How to cherry pick multiple commits from a branch to other?

It is very common practice to pull push and merge the changes from one branch to other branch for developer. Today we are going to see how we could cherry pick changes from one branch to other branch or from feature or working branch to master. Some times we come at a situation where we do not want to merge the complete branch into another branch, instead of complete merge or pull we just want to merge few commits from one branch to another, for that we have cherry pick option in git.

for example we are currently working on branch feature/fix01, and n commits are available on fix01 branch.
Now we want to cherry pick only commit A and B to master branch. to do so, please do the following steps.

Step 1: Open git bash.
git checkout fix01
git log
 $git log command will show all commits, with commit details. From here you can take the commit ID. Alternate to get the commit ID is from git UI, check for the commit SHA. As shown in below screenshot.

 
Step 2: Now checkout the master branch where we need to push the commits.
git checkout master
Step 3: Now run the cherry pick command
git cherry-pick a001 b001 // here a001 and b001 is commit IDs for A and B commit respectively.
if cherry-pick command didn't run successfully and halted due to some conflict, then go to repo and fix the conflicts and then came back to git bash and run the cherry-pick continue command.
git cherry-pick --continue

if you want to stop the cherry-pick or end the process, then run cherry-pick abort command.
git cherry-pick --abort

Step 4: If you cherry-pick was successful then run the git push to move the commits.
git push origin master/master
Step 5: Verify the changes.

References: