pract .pdf

File information

Original filename: pract.pdf

This PDF 1.5 document has been generated by / Skia/PDF m61, and has been sent on on 22/06/2017 at 10:11, from IP address 86.98.x.x. The current document download page has been viewed 304 times.
File size: 32 KB (3 pages).
Privacy: public file

Download original PDF file

pract.pdf (PDF, 32 KB)

Share on social networks

Link to this file download page

Document preview

SessionManager class:
----------------------------------------import java.util.HashMap;
public class SessionManager {
HashMap<Integer, UserSession> list= new HashMap<Integer, UserSession>();
int sessionId = 0;
public SessionManager(){
public int createSession() {
UserSession obj = new UserSession(); = 28;
obj.userName = "test";
obj.createdTime = System.currentTimeMillis();
int newSessionId = ++sessionId;
list.put(newSessionId, obj);
return newSessionId;
public void removeSession(int id) {
public int getSessionCount() {
return list.size();
public UserSession getSession(int id) {
return list.get(id);
public class UserSession {
public int id;
public String userName;
public long createdTime;

public static void main(String args[]) {
SessionManager smanager = new SessionManager();
//to create session
int sessionid = smanager.createSession();
System.out.println("Create new session with sessionid: "+sessionid);
//to get session obj
UserSession ssn = smanager.getSession(sessionid);
//to remove session
//to get count
int count = smanager.getSessionCount();
System.out.println("Number of sessions: "+count);
PING example:
public class pingserver extends Thread{
public void run() {
while(true) {
try {
InetAddress address = InetAddress.getByName("");
System.out.println("Name: " + address.getHostName());
System.out.println("Addr: " + address.getHostAddress());
System.out.println("Reach: " + address.isReachable(3000));
catch (UnknownHostException e) {
System.err.println("Unable to lookup");
catch (IOException e) {
System.err.println("Unable to reach");

try {
} catch (InterruptedException ex) {
}// end of while loop
public static void main(String args[]) {
pingserver obj = new pingserver();

Document preview pract.pdf - page 1/3

Document preview pract.pdf - page 2/3
Document preview pract.pdf - page 3/3

Related documents

java 7 a comprehensive tutorial pg 620 628
recp2 cas sol
c cheat

Link to this page

Permanent link

Use the permanent link to the download page to share your document on Facebook, Twitter, LinkedIn, or directly with a contact by e-Mail, Messenger, Whatsapp, Line..

Short link

Use the short link to share your document on Twitter or by text message (SMS)


Copy the following HTML code to share your document on a Website or Blog

QR Code

QR Code link to PDF file pract.pdf