Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to create a simple Java example, part 2 #16

Closed
sgpennebaker opened this issue Jun 15, 2021 · 6 comments
Closed

Trying to create a simple Java example, part 2 #16

sgpennebaker opened this issue Jun 15, 2021 · 6 comments

Comments

@sgpennebaker
Copy link

sgpennebaker commented Jun 15, 2021

nope, sorry, i'm back and still failing. replaced the jar w java-sdk-1.2.0

the code:

import com.amplitude.Amplitude;
import com.amplitude.Event;

public class AmplitudeSend {

    public static void main( String[] args ) {

        System.out.println( "Hello World!" );

        Amplitude amplitude = Amplitude.getInstance();
        amplitude.init("LET ME KNOW IF YOU NEED THIS" );

        amplitude.logEvent( new Event("ButtonClicked", "test_user_id" ) );
    }
}

the IDE console looks fine.

i go and look at my test project in the Amplitude dash and the count does not increment.

i didn't mention this before but i am able to do curl:

#!/bin/bash
curl --header "Content-Type: application/json" \
  --header "Accept: */*" \
  --request POST \
  --data '{ "api_key": "LET ME KNOW IF YOU NEED THIS", "events": [ { "user_id": "datamonster@gmail.com", "device_id": "C8F9E604-F01A-4BD9-95C6-8E5357DF265D", "event_type": "watch_tutorial", "time": 1622783058 } ] }' \
  https://api2.amplitude.com/2/httpapi

this succeeds and the event count does increment.

if it's helpful, the client is Carbon Health and the project is SGP Test.

thanks in advance!

Originally posted by @sgpennebaker in #12 (comment)

@sgpennebaker
Copy link
Author

let me know if it'd be helpful to zoom or slack or something

@yuhao900914
Copy link
Contributor

Hi @sgpennebaker,
I'm able to reproduce on my side.
I guess it's doesn't matter if the getInstance() has input or not.

May I ask if your main thread has the logic waiting for other threads? If not, that will cause an issue.
We have an async call when calling the server, which will start a thread. But if the main thread terminate early than the daemon thread, the other threads will be killed.

@sgpennebaker
Copy link
Author

@yuhao900914 aha, thanks for the tip - in search of the simplest possible example i skipped the thread part of your example, not understanding it's purpose. so, couldn't hurt to document that, and i apologize if it IS documented and i breezed by it. i'll fix up my example to be better behaved a little later today and update this thread with what i discover. thanks!

@yuhao900914
Copy link
Contributor

Will close this issue since the question got answered. Feel free to reopen or create new ticket if you need other help.

@sgpennebaker
Copy link
Author

thanks @yuhao900914, the code below is good enough for sign of life, but would be good to mention the thread requirement in the "how to" doc at https://developers.amplitude.com/docs/java. i admit i also didn't want to mess with Spring that much, just needed something simple out of the gate. thanks to you and @dantetam for the help!

package com.carbon.amplitude;

import com.amplitude.Amplitude;
import com.amplitude.Event;

public class AmplitudeAsyncSend {

    public static void main( String[] args ) {

        System.out.println( "Hello World!" );

        Amplitude amplitude = Amplitude.getInstance();
        amplitude.init("d32f903389dd1ef7c0cc5a6c978ab13e" );

        amplitude.logEvent( new Event("ButtonClicked", "test_user_id" ) );

        Runnable thread = new Runnable()
        {
            public void run()
            {
                while( 1 == 1 ) { }
            }
        };

        new Thread( thread ).start();
    }
}

@yuhao900914
Copy link
Contributor

Updates: We added the IMPORTANT NOTE to the developer center for this issue.
Thanks for letting us know the potential problem our customer might have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants