pract (PDF)




File information


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 304 times.
File size: 33.05 KB (3 pages).
Privacy: public file












File 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();
}
}






Download pract



pract.pdf (PDF, 33.05 KB)


Download PDF







Share this file on social networks



     





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)




HTML Code

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




QR Code to this page


QR Code link to PDF file pract.pdf






This file has been shared publicly by a user of PDF Archive.
Document ID: 0000615842.
Report illicit content