Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
How to get rid of "Method parameters should be @State classes" in JMH when parameters come from another method?

I'm working on a maven project. The scenario is something like below...

class Test {

    public void applyAll() {
        ....................
        ....................
        Collection<Migratable> applicableUpdates = SomeOtherClass.getApplicableUpdates();
        doUpdate(applicableUpdates);

    }

    @Benchmark
    public void apply(Migratable m) {
        ....................
        ....................
    }

    private void doUpdate(Collection<Migratable> applicableUpdates) throws Exception {
        for (Migratable m : applicableUpdates) {
            try {

                apply(m);

            } catch (Exception e) {
                logger.error("Falid to apply migration {}" + m, e);
                throw e;
            }
        }
    }
}

I need to compute how long it takes to execute each migration. Simply I need to compute the execution time of apply(Migratable m) method.
Now, when I build my project using "mvn clean install", build failed and it shows "Method parameters should be @State classes".

Here, parameter comes from another method doUpdate(Collection applicableUpdates) [see the scenario]. So how can I get rid of this error in given scenario?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

There are quite a few problems in your setup here and it seems you haven't actually looked at the samples of JMH; and I strongly advise you to do that.

A few notes...

1) You @Benchmark method returns void - it should return something; otherwise use BlackHoles (this is in the samples).

2) If parameters comes from another method it means that method should be a @SetUp method (this is in the samples)

3) The error that you are seeing has to do with the fact that your Migratable is not actually a @State class (this is again in the samples!)

At this point I can't stress that enough - but look and understand the samples. It's not going to be easy, this is micro-benchmark and as much as JMH tries to make things easier for us by hiding all the very complicated code, it still requires us to conform to the rules that exist there.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda