PDF Archive

Easily share your PDF documents with your contacts, on the Web and Social Networks.

Share a file Manage my documents Convert Recover PDF Search Help Contact



pract .pdf



Original filename: pract.pdf

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




Download original PDF file









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();
obj.id = 28;
obj.userName = "test";
obj.createdTime = System.currentTimeMillis();
int newSessionId = ++sessionId;
list.put(newSessionId, obj);
return newSessionId;
}
public void removeSession(int id) {
list.remove(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
smanager.removeSession(sessionid);
//to get count
int count = smanager.getSessionCount();
System.out.println("Number of sessions: "+count);
}
}
PING example:
-----------------------------------------import java.net.*;
import java.io.*;
public class pingserver extends Thread{
@Override
public void run() {
while(true) {
try {
InetAddress address = InetAddress.getByName("web.mit.edu");
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 web.mit.edu");
}
catch (IOException e) {
System.err.println("Unable to reach web.mit.edu");
}

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


pract.pdf - page 1/3
pract.pdf - page 2/3
pract.pdf - page 3/3

Related documents


pract
1z0 808 latest dumps free download from lead2pass 161 170
lista6
javaunit3
2 basesjavadebut
c cheat


Related keywords