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 pdf-archive.com on 22/06/2017 at 08: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();
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();
}
}


Document preview pract.pdf - page 1/3

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

Related documents


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

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

QR Code link to PDF file pract.pdf