Re: Calling System.exit()

"Martin W. Kirst" <[email protected]> Wed, 25 May 2011 22:34:41 +0200
Newsgroups gmane.comp.java.tn5250j.general
Message-ID <[email protected]>
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--===============5165628410088898969==
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature";
	boundary="------------enig2D6FC6E0E5D04D8872D09711"

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig2D6FC6E0E5D04D8872D09711
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,

you're right, the class My5250 uses a few System.exit() calls.

This is a little source snippet, which you may use to bootstrap 5250j
yourself ... this way you're avoiding to use My5250j and it's exit() call=
s.

-----------------------------------------------------------
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.Properties;

import javax.swing.JFrame;
import javax.swing.JPanel;

import org.tn5250j.Session5250;
import org.tn5250j.SessionBean;
import org.tn5250j.SessionConfig;
import org.tn5250j.SessionGUI;
import org.tn5250j.interfaces.ConfigureFactory;


public class ExampleEmbeddedMinimalBootstrap {

	public static void main(String[] args) {

		try {
			System.setProperty("emulator.settingsDirectory",
File.createTempFile("tn5250j", "settings").getAbsolutePath());
			ConfigureFactory.getInstance();
			org.tn5250j.tools.LangTool.init();
			final SessionBean sb =3D createSessionbean();
		=09
			JFrame frame =3D new JFrame("TN5250j");
			frame.setSize(1024, 768);
			frame.addWindowListener(
					new WindowAdapter() {
						public void windowClosing(WindowEvent e) {
							sb.signoff();
							sb.disconnect();
						}
					}
			);
		=09
			SessionGUI sessgui =3D new SessionGUI(sb.getSession());
			JPanel main =3D new JPanel(new BorderLayout());
    		main.add(sessgui,BorderLayout.CENTER);
    		frame.setContentPane(main);
			frame.setVisible(true);
			sb.connect();
		=09
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private static SessionBean createSessionbean() throws Exception {

		String system =3D "127.0.0.1"; // TODO: your IP/hostname

		SessionBean sessionBean =3D null;
		SessionConfig config =3D new SessionConfig(system,system);
		config.setProperty("font", "Lucida Sans Typewriter Regular"); //
example config

		Session5250 session	=3D new Session5250(new
Properties(),system,system,config);

		sessionBean =3D new SessionBean(session);

		sessionBean.setHostName(system);
		sessionBean.setCodePage("Cp273");
		sessionBean.setNoSaveConfigFile();
		sessionBean.setScreenSize("27x132");
		sessionBean.setDeviceName("devname");

		return sessionBean;
	}

}
-----------------------------------------------------------

Regards
 Martin

Am 25.05.2011 15:02, schrieb Arpe, Kevin C:
> Hi,
>=20
> I noticed in your code you call System.exit() in a few places.
> Example: org.tn5250j.My5250.main()
>=20
> This makes it difficult to call this method from other Java code.
>=20
> Is there a recommended way to spawn new connections using the same virt=
ual machine?
> Example: I want to spawn your app from another app.
>=20
> On idea, is call java.exe externally and pass the JAR name.
> But I would rather call into your JAR directly -- same virtual machine =
(VM).
>=20
> When I use a basic threading design, it won't work because System.exit(=
) terminates the VM.
> However, I built a very basic SecurityManager to trap calls to System.e=
xit().
> [Source: http://stackoverflow.com/questions/309396/java-how-to-test-met=
hods-that-call-system-exit]
> Now my solution works... but it is a slight hack.
>=20
> Can you please provide the correct API calls... or remove System.exit()=
 from your code?
>=20
> We are big fans here.  Keep up the good work.
>=20
> Please advise.
> Thanks,
> Arpe
>=20
>=20
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email. =20
>=20
>=20
>=20
> -----------------------------------------------------------------------=
-------
> vRanger cuts backup time in half-while increasing security.
> With the market-leading solution for virtual backup and recovery,=20
> you get blazing-fast, flexible, and affordable data protection.
> Download your free trial now.=20
> http://p.sf.net/sfu/quest-d2dcopy1
>=20
>=20
>=20
> _______________________________________________
> Tn5250j-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/tn5250j-general



--------------enig2D6FC6E0E5D04D8872D09711
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3dZ+EACgkQefmD4St1GNHFcwCeNj2HaudoogexVmKpCM49vXqf
TCMAoNeU6eu2QngWOrUGyNiCZop5l8k5
=vIcI
-----END PGP SIGNATURE-----

--------------enig2D6FC6E0E5D04D8872D09711--


--===============5165628410088898969==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery, 
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now. 
http://p.sf.net/sfu/quest-d2dcopy1
--===============5165628410088898969==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tn5250j-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tn5250j-general

--===============5165628410088898969==--