Synchronize a String

I am new in Threading and I’m haveing a problem with a test.

This is my main:

public class mainn {

public static void main(String[] args) {

    Writer w1 = new Writer("1");
    Writer w2 = new Writer("2");
    Writer w3 = new Writer("3");
    Writer w4 = new Writer("4");
    Writer w5 = new Writer("5");



So, im basically running 5 threads almost simuntanlly. This is the Writter class:

public class Writer extends Thread {

    static String all = "";

    String number;

    public Writer(String number) {

    this.number = number;


 public void run() {

        synchronized (all) {

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

            all += number;


        System.out.println("End of thread "+number+": "+all);


So, the output should be something like (for a loop of 5):


but its like


So, if i want to “block” the String “all”, do the syncronize and after let another thread to go in (doesn’t matter the order, I only want to block the string while I do the loop) what should I do?

Deploy *.war file with parameters

I have web project with REST API. I want to deploy 5 copies of it on tomcat server. For example:
test1.war => URL: http://localhost:8080/test1/api
test2.war => URL: http://localhost:8080/test2/api
test3.war => URL: http://localhost:8080/test3/api

The problem is that each war file should use different config file. I know that I can set env variables using export CATALINA_OPTs="Dparam1=/usr/config1.txt". Then I need to change source code inside each war file in order to read param1 for test1.war, param2 for test2.war. But each war file should be the same (only different names_ Theoretically the perfect solution is something like this:

deploy test1.war -conf <path1>
deploy test2.war -conf <path1>

Is it possible to do in in the tomcat? Is there any alternative for doing this?

Android – Cannot retrieve data from Firebase

I am drawing a route between two markers, and I want to save that route. To do that I saved the ArrayList containing the lat and lng in the Firebase database. But I am having problems retrieving the waypoints. This is how I inserted:

This is how I am inserting:

String routeId = database.push().getKey();
database.child(sharedPreferences.getString("school", null)).child("routes").child(routeId).setValue(points);
SharedPreferences.Editor editor = getActivity().getSharedPreferences("sh", MODE_PRIVATE).edit();
            editor.putString("key", routeId);

where the sharedPreferences string “school” is the name of the school. routeId is a push() key and the points is an arraylist of waypoints.

My database:enter image description here

My POJO classes:

public static class Route {

    private ArrayList<Location> locations;

    public Route() {

    public ArrayList<Location> getLocations() {
        return locations;

    public void setLocations(ArrayList<Location> locations) {
        this.locations = locations;

public static class Location {
    private Double latitude;
    private Double longitude;

    public Location() {

    public Double getLatitude() {
        return latitude;

    public void setLatitude(Double latitude) {
        this.latitude = latitude;

    public Double getLongitude() {
        return longitude;

    public void setLongitude(Double longitude) {
        this.longitude = longitude;

Retrieval of waypoints:

  points = new ArrayList();
    userRef.child(sharedPreferences.getString("school", null)).child("routes").child(sh.getString("key",null)).addListenerForSingleValueEvent(new ValueEventListener() {
        public void onDataChange(DataSnapshot dataSnapshot) {
            Route route = dataSnapshot.getValue(Route.class);
            for (Location location : route.getLocations()) {
                double lat = location.getLatitude();
                double lng = location.getLongitude();
                position = new LatLng(lat, lng);

But I am getting a database exception: “DatabaseException: Can’t convert object of type java.util.ArrayList to type packagename” I don’t know why

how to load balance between IBMMQmanager via mq-client in application

I have multiple IBMMQQueueManager on which i have to loadbalance and connect to the queues hosted on queuemanager. I have HA configuration for QueueManager but I don’t see and example for that. CAn someone help me understand this configuration so that I can easily load balance between queuemanager from client application.

Also It would be great if someone could help me with this configuration on camel.

OpenNLP NameFinder Custom Feature generation

I would like to train a own model to use in OpenNLP NameFinder.

Searched a lot and finally came up with a working code to train a model, but its not accurate. The documentation also says you need 15000 sentences to have a accurate model.

So you need to have 15000 sentences with a good context and at the name every time <START> <END>. To do this you would have to spend hours
days/months writing a .txt file.

I did some futher search to train a model without writing all by your self and came on Custom Feature generation of OpenNLP.

But it says not much about how to use it. The documentation gives this :

AdaptiveFeatureGenerator featureGenerator = new CachedFeatureGenerator(
     new AdaptiveFeatureGenerator[]{
       new WindowFeatureGenerator(new TokenFeatureGenerator(), 2, 2),
       new WindowFeatureGenerator(new TokenClassFeatureGenerator(true), 2, 2),
       new OutcomePriorFeatureGenerator(),
       new PreviousMapFeatureGenerator(),
       new BigramNameFeatureGenerator(),
       new SentenceFeatureGenerator(true, false)

Does somebody knows how to use this? Or much better, is someone already successful to train his own model for OpenNLP NER without typing him self the data set?

Thanks in advance.

Android Null pointer Exception on GLSurfaceView

I am having one GLSurfaceView fragment and i am loading one dialog on top of this view for some Bluetooth operation. The dialog is launched successfully. But while performing the some button click on this dialog i am getting below error.


From the dialog i am not accessing any openGL resource.

Any idea why its happening???

best way save data 2D array in java

i’ve a problem about saving 2d array’s value to hardisk. i build 5000×5000 item similarity table (float) and i want to store it because it will be continuesly used. i’ve tried save them to .txt file by format index1,index2,value+n and they’re growing to 250MB of size (its approx 25million of rows). is there any ways to reduce its size?
i would be glad if anyone mind to help me

Is mock configuration propagated to other threads in mockito?

I have a test consisting of a thread running test code and another thread running the system under test. The SuT contains some mocks being configured in test thread.

The behavior of my test is: It does on my local machine what it should. On our build server it doesn’t. As far I have debugged, the problem is, that mock doesn’t behave like configured.

So it seems to me like my configuration from test thread (in some circumstances) is not propagated to sut thread.

Could this be the problem? Is Mockito not thread-safe in such use cases?

Cannot create WifiConfiguration in Android Studio

I am trying to create a WifiConfiguration, however, if I write the following:

WifiConfiguration conf = new WifiConfiguration();
conf.SSID = String.format(""%s"", ssid);

The ide gives this error:

unknown class: conf.SSID

I also tried the following code:

WifiConfiguration conf ;
conf = new WifiConfiguration();

However, it now gives the error:

Invalid method declaration

What could be wrong? I do have the


at the beginning of my file