Bilal Ghayad

Ranch Hand
+ Follow
since Sep 29, 2018
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Bilal Ghayad

Maybe I did not explain well what I need to do.
First of all, I am talking about my website which has visitors from all places, not employees in the office.
I have form and I need the visitor to fill data and I need this data to be sent by email for me.
What is the easiest simple and safe way? Can I do it in JavaScript and to be secure?
That is why I was asking about using email.js.

Appreciate the kindly help.
Regards
Bilal
Dears;

I need to use email.js to send email from javascript directly without the use for server side code, but I am afraid from the security because in this case, I have to place in the javascript code the username and password of the email and this will give a chance for the hackers to use my smtp account to send emails and that will cause a lot of problems. How I can overcome this problem? I do not need the hackers to be able to see the the javascript code that is sending the email. How?

Regards
Bilal
Dears;

Same as Java (server side), we can see the System.out.println messages in the tomcat logs or in the Eclipse Console, how can we see the print messages of the php which we need to use it in the debugging at the linux command line in order to do debug the server side code (when connecting to database and manipulating results and so on)?

Regards
Bilal
3 months ago
PHP
Thank you for your help and kindly advise.

Please make sure that when you say "classes" you mean actual Classes and not instances of Classes (objects). You don't want to be compressing the wrong thing.



Actually I displayed what I see in the journal logs which is related to class-load, so based on that I said classes as it is displayed by class-load as shown in the below line (as sample of the logs):



Now coming to the sessions and EntityManagers, actually when creating session, I am using:
StandardServiceRegistry, SessionFactory and session and when I need to close it, then I use session.close() and session.getSessionFactory().close(). So I am in wrong direction? Can you please put me in the right track?

Moreover, can I know why the using of sessions is causing this class loader problem which cause the out of memory because Compressed Class Space is full?

Again, I am really very thankful for your great help and advise.
Regards
Bilal
1 year ago
Hello All;

I am using Spring MVC version 5.3.29 with Hibernate version 5.6.15.Final, and I am getting Out of Memory Because Error Compressed Class Space although I set the size to be 3g using the argument -XX:CompressedClassSpaceSize=3g. In order to detect where is the memory leak happening and which class is keep loaded again and again, so I added the following argument for JVM: -Xlog:class+load=info  and we discovered that there are some classes which are hibernate model classes (classes defined to be mapped to the tables) are loaded and loaded again (based on the below obtained tomcat log). Please note that we are using session.createNativeQuery recently and some queries are still session.createSQLQuery.

In the hibernate model classes (that I created), I imported the following:



I am closing the sessions using session.flush(), session.clear(), session.close() and session.getSessionFactory().close().
Moreover, I am using the below hibernate dependency:



Please see the below results of the class-load logs which contains "__JVM_DefineClass__":



And ofcourse, the Compressed Class Space is keep increasing until I reach for out of memory.
Tomcat version is 9
JDK version is 17.
Operating System is Linux Ubuntu Server version 22.04.2 LTS

Appreciate the kindly help please.
Regards
Bilal
1 year ago
Thank you a lot Tim for your kindly information and reply.

What about:

SEVERE: Socket accept failed
java.net.SocketException: Too many open files (Accept failed)



Do you have any advise on how to fix it?
Regards
Bilal
2 years ago
Hello All;

I am facing tomcat crashes with the following errors:

SEVERE: Socket accept failed
java.net.SocketException: Too many open files (Accept failed)
Out of Memory



I have really some questions that can help me to solve these errors please:

When I login to the tomcat management and I go to the Server Status, I see the following which are related to the threads, is it normal? Or there is something I have to change?

1) Threads monitoring:

Max threads: 400 Current thread count: 50 Current thread busy: 2
Max processing time: 73776 ms Processing time: 1231.185 s Request count: 2819 Error count: 1198 Bytes received: 0.18 MB Bytes sent: 148.64 MB

Stage Time B Sent B Recv Client (Forwarded) Client (Actual) VHost Request
P ? ? ? ? ? ?
R ? ? ? ? ? ?
R ? ? ? ? ? ?
R ? ? ? ? ? ?
R ? ? ? ? ? ?
R ? ? ? ? ? ?
R ? ? ? ? ? ?
R ? ? ? ? ? ?
S 13 ms 0 KB 0 KB 10.30.250.26 10.30.250.26 10.22.28.38 GET /manager/status HTTP/1.1
R ? ? ? ? ? ?
R ? ? ? ? ? ?
R ? ? ? ? ? ?
R ? ? ? ? ? ?
R ? ? ? ? ? ?
P: Parse and prepare request S: Service F: Finishing R: Ready K: Keepalive

Why the stages of the threads are still appearing even if they are Ready? Should not be disappeared? If I restarted the tomcat, I do not see them, it means that it started clean, so why they are appearing even after long time of not using the application (maybe after 6 hours of not using).

2) Opened files and lsof command:

When I type the command lsof -p process_id, I see a lot of the following lines (IP: 10.22.22.20 is the database server) although I close every database session that I open it in the code:

java    9874 tomcat   61u  IPv6          100650058       0t0        TCP localhost.localdomain:38190->10.22.22.20:cichild-lm (ESTABLISHED)

By the way, I do not use IP version 6.
Of course when tomcat is restated, I do not see this line. But after start using it, they start appearing and they do not disappear even if we stopped working. I am worry that I missed something that is causing them to stayed opened which will cause the above mentioned errors which are causing the tomcat to crash.

I know that I have to close every database session that I created in the code, and I know that I have to close every HttpurlConnection and every socket and every stream in the code. What else should I do?

Your kindly help is highly appreciated.
Regards
Bilal
2 years ago

I usually launch Tomcat either from my IDE or the command line.



I mean from eclipse, how?

Because, when I was using JDK 8, I was running the Spring MVC application with tomcat as following:

Run As --> Maven build --> At the Goals, I type: tomcat7:run

And of course in my pom.xml and as you saw, I was having the below configuration:



So my question: are you running tomcat9 using tomcat:run when running the application by Maven build, or you configured tomcat 9 as server and you are running it using Run On Server?

Regards
Bilal
3 years ago
OK and how you run tomcat?
You run it using tomcat:run or how?

Do you have the pom.xml file?

Regards
Bilal
3 years ago

I have found that Java 11, Tomcat 3.9 and Maven 3.8 are a stable working point at the moment. I have not attempted to live on the "bleeding edge".



Tomcat 3.9? That is very very old, it is older than tomcat 7. Why to go for this very old version??

I am placing the pom.xml below between code:



Regards
Bilal
3 years ago
Is it required from me to upgrade my JDK or I can stay with JDK 8?
The problem that new eclipse versions are not working with JDK 8.

Now, I installed JDK 17, but really I am facing a problem in two things:
1) The pom.xml file: which versions and dependencies?
2)  When I was using JDK 8, I was able to run the application using tomcat7:run, now it is not working and it is giving me a lot of errors.

So shall I stay with JDK 8?
If it is needed to work with JDK 17, so which tomcat version is needed and which spring framework, hibernate and maven versions are needed?

Below is my pom.xml:


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aliat</groupId>
<artifactId>alm</artifactId>
<name>ALM</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>17</java-version>
<org.springframework-version>5.3.15</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
<hibernate.version>5.4.32.Final</hibernate.version>
</properties>
<dependencies>
 <!-- com.microsoft.sqlserver -->
       <dependency>
           <groupId>com.microsoft.sqlserver</groupId>
           <artifactId>mssql-jdbc</artifactId>
           <version>8.4.1.jre8</version>
       </dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.13.1.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-keyvalue</artifactId>
<version>1.2.1.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>

<!-- Spring ORM -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>

<dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-core</artifactId>
       <version>${org.springframework-version}</version>
    </dependency>

<dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-tx</artifactId>
       <version>${org.springframework-version}</version>
    </dependency>

<dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-beans</artifactId>
       <version>${org.springframework-version}</version>
    </dependency>


<!-- jsch -->

<dependency>
  <groupId>com.jcraft</groupId>
  <artifactId>jsch</artifactId>
  <version>0.1.44-1</version>
</dependency>


<!-- hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<exclusions>
   <exclusion>
               <groupId>xml-apis</groupId>
               <artifactId>xml-apis</artifactId>
            </exclusion>
</exclusions>

</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-jpamodelgen</artifactId>
  <version>5.4.32.Final</version>
  <optional>true</optional>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
</dependency>


<!-- oracle -->

<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>


<!-- poi Excel -->

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
<exclusions>
<exclusion>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- ENd poi Excel -->

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.2.Final</version>
</dependency>

<!-- AspectJ -->

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.0</version>
</dependency>

<!-- JSON -->

<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>


<!-- Logging -->

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>

<!-- @Inject -->

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>


<!-- Servlet -->

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>


<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>


<!-- json -->

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>


<!-- json2 -->

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
</dependency>

<!-- apahce lang3 -->

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>

<!-- Email -->

<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.5</version>
</dependency>
<!--  Google Maps Dependencies -->
<dependency>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-services</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>

</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>

</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>

</configuration>
</plugin>

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<contextReloadable>true</contextReloadable>
<port>8080</port>
</configuration>
</plugin>
</plugins>
</build>

</project>



Regards
Bilal
3 years ago
Currently I am using JDK version 8 (it is outdated).
So, I can understand it is recommended to move to JDK 17.

Regards
Bilal
3 years ago
Hello;

I have to upgrade from JDK 1.8 for my Spring MVC project as it is outdated.
So what is the recommended JDK to go for it?
Should I go for JDK 11 or 17?

Also, what is the recommended Spring and Maven to be used with the recommended new JDK?

Thanks
Regards
Bilal
3 years ago
Thanks a lot for your kindly help and reply.

Actually tomcat is stay working (up and running) but to be able to navigate my application pages, I have to restart the tomcat.
I am using try catch as much as I can, but the question is:
Let us assume there is one place we did not place try and catch, and the application faced the error, so why I have to restart the tomcat to be able to resume the work on the application? I can understand that it will display error at the page that the error occurred but if we clicked on back or if we tried to navigate any other page, it should resume the work without need to restart the tomcat.

How to resolve this problem?

Regards
Bilal
3 years ago
Hello;

My application is Spring MVC.
I use try catch finally block and even in my database queries I try to avoid getting null result as much as I can. But sometime and for some reason, an error is happening (due to something was not expected). The problem that tomcat 7 (which is running in CentOS) is crash and then we need to do  restart for it to be able to resume the work.
How can I avoid this? We need tomcat to keep running, so the user can resume his work while navigating other pages which does not contain any problems and of course we are monitoring the error logs and we can work to resolve the reason for the error, but we need tomcat to stay working and not crash, how to do this? What kind of configuration is needed?

Regards
Bilal
3 years ago