Win a copy of Head First Android this week in the Android forum!

Vijay Kumar Raman

Greenhorn
+ Follow
since Oct 19, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vijay Kumar Raman

When a command is executed via SSH connection, often the command execution fails with Exception - "net.schmizz.sshj.connection.ConnectionException: Connection reset Exception is thrown".

Problem description:
------------------------

I created a SSH connection instance to a host using net.schmizz.sshj.SSHClient. I execute bunch of commands using this SSH connection and finally close the connection.
In times SSH command execution fails with exception saying,

2018-04-11T12:02:51.755Z INFO  c.v.v.u.SSHUtil [executeRemoteSSHCommand:861] [main] - Successfully executed 'tar -C /usr/local/ -zxvf /usr/local/VMware-GuestSDK-10.2.0-8225092.tar.gz --no-same-owner' command on remote ssh host
2018-04-11T12:03:18.121Z ERROR n.s.s.t.TransportImpl [die:589] [reader] - Dying because - {}
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at net.schmizz.sshj.transport.Reader.run(Reader.java:50)
2018-04-11T12:03:18.123Z INFO  n.s.s.t.TransportImpl [notifyDisconnect:182] [reader] - Disconnected - UNKNOWN
2018-04-11T12:03:18.127Z ERROR n.s.c.Promise [tryRetrieve:175] [main] - <<chan#6 / open>> woke to: net.schmizz.sshj.connection.ConnectionException: Connection reset

2018-04-11T12:03:18.130Z ERROR c.v.v.e.OutcomePrinter [afterInvocation:40] [main] - exception thrown
net.schmizz.sshj.connection.ConnectionException: Connection reset
at net.schmizz.sshj.connection.ConnectionException$1.chain(ConnectionException.java:32)
at net.schmizz.sshj.connection.ConnectionException$1.chain(ConnectionException.java:26)
at net.schmizz.concurrent.Promise.deliverError(Promise.java:96)
at net.schmizz.concurrent.Event.deliverError(Event.java:74)
at net.schmizz.concurrent.ErrorDeliveryUtil.alertEvents(ErrorDeliveryUtil.java:34)
at net.schmizz.sshj.connection.channel.AbstractChannel.notifyError(AbstractChannel.java:226)
at net.schmizz.sshj.connection.channel.direct.SessionChannel.notifyError(SessionChannel.java:224)
at net.schmizz.sshj.common.ErrorNotifiable$Util.alertAll(ErrorNotifiable.java:35)
at net.schmizz.sshj.connection.ConnectionImpl.notifyError(ConnectionImpl.java:258)
at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:597)
at net.schmizz.sshj.transport.Reader.run(Reader.java:68)
Caused by: net.schmizz.sshj.common.SSHException: Connection reset
at net.schmizz.sshj.common.SSHException$1.chain(SSHException.java:36)
at net.schmizz.sshj.common.SSHException$1.chain(SSHException.java:29)
at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:591)
... 1 common frames omitted
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at net.schmizz.sshj.transport.Reader.run(Reader.java:50)
2018-04-11T12:03:18.131Z INFO  c.v.v.e.OutcomePrinter [afterInvocation:47] [main] - OUTCOME:FAIL

Issue:
--------

often the SSH connection disconnects and reconnects but when I execute a command via this SSH connection and in that time if the disconnect happens, it never reconnects instead net.schmizz.sshj.connection.ConnectionException: Connection reset Exception is thrown.

My Query:
------------

How to overcome this ssh disconnection issue from my Java code especially while executing commands via the SSH connection ?

Thanks.
3 years ago

output : 8

x++ + x++ * --x
2 + x++ * --x
2 + 3 * --x
2 + 3 * 2
2 + 6
result: 8
Is this correct ?
4 years ago
I tried writing a program to throw a Error object explicitly and written try catch block to handle the Error. It is working !!!
Even when I try throwing a Throwable object also it works just fine.
Can anyone tell me why we are allowed to write Throwable or Error in catch block while writing Exception alone would be more relevant :-)



Console output:
java.lang.Error
at ErrorCheckTry.testingthrowError(ErrorCheckTry.java:3)
at ErrorCheckTry.main(ErrorCheckTry.java:8)
Error caught in catch block

Note: I tried adding a recursive call of the testingthrowError() method above. Program terminated throwing StackOverflowError. The catch block does't work here !!!

[Added code tags - see UseCodeTags]
9 years ago
If you see the System class, the reference variable out is not initialized
public final static PrintStream out = nullPrintStream();
where method call nullPrintStream() returns null

then how the out.println() method call works ?
9 years ago
I tried to call a method of a class for which I have created static final reference variable (not instantiating any new object) just like in System.out.println() as below,



The instance variable declaration line in CheckStaticObjRef .java class, "public static final StaticObjClass stob;" is giving compilation error "The blank final field may not have been initialized". I dont know where am missing something in my code.
Kindly help.

[Added code tags - see UseCodeTags]
9 years ago
How to prevent duplicate data entry in hibernate while more than one insertion done being simultaneously (by two different processes) that have auto generated primary key?
Our application will insert record to a mysql table with auto generated primary key and using hibernate 3 and MYSQL 5.5.21. But when the same application is running in more than one PC and both trying to insert record in the table simultaneously, I get the exception as below

org.hibernate.util.JDBCExceptionReporter:logExceptions(78) | Duplicate entry 'somevalue' for key 'PRIMARY'.

Kindly help to resolve this issue.
In Tomcat 6.0 I need to increase the heap memory size to 100MB, Tomcat is not running as windows serive in my PC and I don't have admin rights to change the heap meory size in tomcat6w monitor window.
I tried giving set JAVA_OPTS=-Xmx1024m -Xmx1024m and set CATALINA_OPTS=-Xmx1024m -Xmx1024m in tomcat console and also tried creating a setenv.bat file (since I am working in Windows OS) explicitly in Apache Software Foundation\Tomcat 6.0\bin\ foder but it is also not working it seems.
9 years ago
Hi,
I have developed a web application that runs on Tomcat6 (run from console \bin and not as windows service) and uses hibernate 3 for OR mapping and MYSQL as database. my requirement is I have to upload files of size upto maximum 100MB and persist them in a table column in the database using hibernate.

I read the FileInputStream directly into Hibernate Blob object using Hibernate.createBlob(FileInputStream obj) method. In hibernate Pojo class and hbm.xml file the corressponding column name type is declared as blob. when I execute this application I am able to upload files of size upto 25MB successfully. but when i try to upload file of size greater than 25MB it is throwing OutOfMemoryError: Java heap space

java.lang.OutOfMemoryError: Java heap space
at com.mysql.jdbc.Buffer.<init>(Buffer.java:59)
at com.mysql.jdbc.MysqlIO.sendSplitPackets(MysqlIO.java:3765)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3296)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1983)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427)
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1980)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1451)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)

I tried commenting the hibernate session.save(objref); call and I am not getting the OutOfMemoryError.

Note: I am not supposed to use byte array to read the inputstream data into and then store it in database using hibernate since memory is a constraint for me. In mysql the max_allowed_packet size is 1024MB. kindly help.
Thanks for the clarification. I will post my query in hibernate OR mapping forum.
9 years ago
I tried modifiying the JAVA_OPT and CATALINA_OPT environment variable's values to 1GB but still getting the same exception "outofmemoryerror". I believe my current approach which reads the whole file from FileInputStream and stores it in a byte[] array and finally storing the byte[] array to the database is giving problem since it requires the whole file should be stored in memory before persisiting into database. Is there any approach in hibernate 3.0 to store large files in database and without ctoring them in memory (RAM).

I need alternative solution to modify my application code to handle large files rather than modifying the application server environment variables values since my application will be deployed in different application servers.

Thanks.
9 years ago
Hi,
I need to increase JVM Heap size in Tomcat 6.0 to 100MB. I am running a web application in Tomcat6 using whcih I should upload and download file attachments of size upto 100MB.
I start Tomcat6 from the console mode. i.e, D:\Program Files\Apache Software Foundation\Tomcat 6.0\bin>tomcat6.exe.
I tried increasing heap size from command prompt by setting hte environment variables CATALINA_OPT and JAVA_OPT. it didnt help either. please help. Tomcat is not running as a windows service in my PC either.
9 years ago
I am trying to upload file (size 1MB to 100MB) through my web application running in Tomcat 6 and ultimately storing the file in a database table column using hibernate 3.0 as BLOB data in MySQL database. I am able to upload and save files of size upto 10MB successfully (Though I get the same OutofMemory error). But when I try to upload and save file of size more than 10 MB, I am getting below Error message,

Caused by: java.lang.OutOfMemoryError: Java heap space
at com.mysql.jdbc.Buffer.<init>(Buffer.java:59)
at com.mysql.jdbc.MysqlIO.readRemainingMultiPackets(MysqlIO.java:3135)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3089)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2991)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3532)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943)
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1441)
at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2936)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:477)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2631)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1800)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2221)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)

The max_allowed_packet size in MYSQL is 1GB and I tried changing the heap size in tomcat console as set CATALINA_OPTS="-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m" and JAVA_OPTS="-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m". Also I explicitly added catalina.bat and catallina.sh files in tomcat/bin folder with the same CATALINA_OPTS and JAVA_OPTS values.

On executing the application in tomcat the uploaded file is correctly copied into D:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\<MyApp> folder and the logging statment is written upto session.save(hibernatepojo object ref) method in data layer.

PS: The same application executed as standalone application using main method uploads file of size 120MB successfully without throwing any error.

Kindly help. Thanks.
9 years ago
I have a standalone java application (With a UI screen with login page in Applet and AWT) which i have to distribute to my clients as EXE. The client will simply add the exe in the desktop and on clicking the icon the application should be launched displaying the Login screen. kindly help....
11 years ago