amithk kumar

Greenhorn
+ Follow
since Aug 27, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by amithk kumar

i have configured these below classes as it is annotation configuration. Iam getting 404 not found while accessing this path /oauth/token. can anyone guide on this.


for web configuration



for configuring the security



for security filter



for authorization server

7 years ago
I am new to Spring Oauth2. I created two classes SecurityConfig for basic spring security configuration and AuthorizationServer  for spring oauth2 authorization server configuration

What i learned from spring security in  configure method of the below code is that  User Named test is assigned a role of USER.



and when



 the configure(HttpSecurity http) is configured , any url that is accessed in the code  will need a basic authentication and user must provide his/her username and password to access the urls.

This is about spring security


can anyone explain that


this will  call configure(AuthenticationManagerBuilder auth)
of the SecurityConfig.java?


and what will endpoints.authenticationManager(authenticationManager); method does from the below code?





7 years ago
i have created a class called hotel  in which  i have set a boolean variable called conditionVar to false. inside the run method i have used two synchonized blocks, one is for wait and other is for notify .But the application is showing output as




it is not entering in the synchronized block of notify . Is this an concept of busy waiting? and how can the thread call notify?





Two classes factor and addition

factor is having val variable that means it is shared across multiple threads (in the current application we are using two threads).

addition class is having a add variable it is also shared across multiple threads, because it's instantiated in factor class.

my question is

1)if synchronized(this) is used, which means that any of the two threads will lock on factor instance and increment val variable value till the loop exits.
   so synchronized(this) means here that we should not use any other instance variables. We have to use only the variables of factor instance inside the synchronized block?

2) if synchronized(addition) means here that we have to use only  add variable not the val variable of factor instance class?


There is a big confusion regarding this synchronization block .
what i understood  is synchronization block will lock on the object's instance and guard the operation and make it thread safe. But using different instance really means that it should guard only that particular instance variables not any other instance variables. Can anyone explain in depth concept regarding this relating with the code provided below

The factor class



The addition class



   The main class



   




The main program








i have created a class called counter and initialized a variable c . When called on increment method it increments by 1. When called on decrement method it decreases by 1.

There is one more method called getVal which will return the c value. These methods i have added synchronized keyword for the methods


In the main program i am sharing the counter object in the loop. I am looping and creating threads and starting them but while running even though i have added synchronized method iam getting output like this


the increment case Thread--->72
the value case Thread--->72
Thread--->72 incremented 1
the decrement case Thread--->72
the value case Thread--->72
Thread--->72 decremented 0
the increment case Thread--->76
the value case Thread--->76
Thread--->76 incremented 1
the decrement case Thread--->76
the value case Thread--->76
Thread--->76 decremented 0
the increment case Thread--->80
the value case Thread--->80
Thread--->80 incremented 1
the increment case Thread--->22
the increment case Thread--->124
the increment case Thread--->2
the increment case Thread--->116
the value case Thread--->116
the increment case Thread--->120
the value case Thread--->120
Thread--->120 incremented 6
the decrement case Thread--->120

Thread 72 and Thread 76 are printing correctly first it is increasing the value so it is 1 and then decreasing value so it is 0.

but if you see Thread 22 and Thread 124 and Thread 2 and so on the value of c variable reached to 6 . This is what iam confused even though adding synchronized keyword it is behaving very different


But if i add synchronized block like this in run

iam getting the expected output .Why it is happening , whether the synchronized keyword for those methods are not enough?do i have to use the synchronize for run only?

Can someone explain about re entrancy according to this code?
1)question is if i use synchronized method it will acquire the lock for the test object or for both proce and test object.

Because the value are printing correctly when i used synchronized method while calling getVal method from test class

2) If i use synchronized block in getInc and acquire lock for test class for example like this
what will happen automatically var variable of proce class will be synchronized?

here are the classes which i have used


In the below program i have created a thread and made it as daemon thread using setDaemon(true) and created Two String objects when ever i run this the console shows this output

main thread=non daemon thread
before for s1 0
before for s2 0




public class DaemonTest {
public static void main(String[] args){
Runnable obj = new Runnable()
{

String s1=new String();
String s2=new String();
public void run()
{
System.out.println(" s1 "+s1.hashCode());
System.out.println(" s2 "+s2.hashCode());

try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println(s1.hashCode());
System.out.println(s2.hashCode());
System.out.println("inside run");
}
};
Thread t = new Thread(obj);
//t.setDaemon(false);
t.setDaemon(true);
t.start();
System.out.println("main thread=non daemon thread");
}
}


1)why s1 and s2 hashcode value is zero

2) after JVM exits what happens to the s1 and s2 string objects will they be collected by garbage collector ?
I have two classes one is main method other is a class which implements runnable interface.

I want to print threads in console of order t3 then t2 and then t.

I read in the internet that the order can be ensured by calling thread.join() inside run but was not able to pass t3 and t2 and t thread objects to the class which implements runnable.

how to pass thread objects to the class and call t3.join and t2.join and t.join inside run method

here are the classes which i have written are






i think my eclipse is behaving weird actually when getinstance is returning null the getinstance.hashcode should throw null pointer exception but sometimes aim able to see concurrentmodificationexception
here is the class

public class InsSingleton implements Runnable {

public List<Integer> list = new ArrayList<>();

public int cnt = 0;


// Adding hashcode values to a list
@Override
public void run() {

list.add(SingleTon.getInstance().hashCode());

Collections.synchronizedList(list);

}

}



even though using collections.synchronized list the output is having null and other hashcode value
I have created a main class and ran a thread for 10000 tines each time it hits run method it will call l SingleTon.getInstance method and adds hashcode to a list but i am wondering why iam getting

output like this even though the getinstance method of SingleTon is synchronized

[1388889817, 1388889817, 1388889817, 1388889817, 1388889817, 1388889817, 1388889817, 1388889817, 1388889817, 1388889817, null, ...so on

here the unique hashcode which iam able to see
[null, 1388889817] why null is there only the hashcode 1388889817 should be present.


public class InsSingleton implements Runnable {

public List<Integer> list = new ArrayList<>();
public int cnt = 0;


// Adding hashcode values to a list
@Override
public void run() {

list.add(SingleTon.getInstance().hashCode());

}

}


public static void main(String[] args) throws InterruptedException {

List<Integer> list = new ArrayList<>();

InsSingleton insSingleton = new InsSingleton();

for (int i = 0; i < 10000; i++) {

new Thread(insSingleton).start();
}

list = insSingleton.list;

Set<Integer> set = new HashSet<>();
Set<Integer> set1 = new HashSet<>();

for (int i = 0; i < list.size(); i++) {
// checking what hashcode are added in list
if (set.add(list.get(i)))
set1.add(list.get(i));

}

// printing the hashcodes
System.out.println(list);
System.out.println(set1);

}


public class SingleTon {

private static SingleTon singleTon = null;

//private constructor
private SingleTon() {

}

//synchronized method
public static synchronized SingleTon getInstance() {

if (singleTon == null) {
singleTon = new SingleTon();
}

return singleTon;

}

}







Can anyone guide me as iam trying to learn java.util.concurrent topics by creating a simple web application that uses servlets and jsps and jdbc, server is tomcat server.

As iam new to java.util.concurrent just want to know where it is used in web applications. if so what topics are used while designing a java.util.concurrent iam using only singleton and DAO patterns.

I just want to know what topics and where it is used at both web layer and database layer.

Iam trying to create a login page where login page has two options
1) here he can login as user, user can update and view only his details.
2)here as admin. as admin he can update delete and view all the users.

here where multithreading concepts such as thread local is used or java.util.concurrent topics such as executor barriers etc are used.

please guide