« Return to Thread: future hangs

Re: future hangs

by Marcus Downing :: Rate this Message:

Reply to Author | View in Thread

I see, thanks. That's quite a gremlin.

Arthur Peters wrote:
If you look at the bottom of the blog post
(http://scala-blogs.org/2008/07/application-trait-considered-harmful.html)
you will see:

First, concurrency is broken. The JVM does not allow other threads to
access a class during initialization. You can easily get yourself into
deadlock by writing concurrent code in classes that use Application.
(See Ticket #746)

The basic idea is that threads are not allowed to run concurrently
with the initializer. So the thread that sets the future never runs.

-Arthur



On Tue, Jul 7, 2009 at 9:29 PM, Marcus Downing<marcus@minotaur.it> wrote:
>
> Can somebody explain why that makes it work? What about the Application class
> would break a future? Or what else is going on?
>
>
> turicum wrote:
>>
>> it works! thanks!
>> Alessandro
>>
>>
>> Mark Harrah wrote:
>>>
>>> Don't use Application.  Just use a normal main method.  See
>>> http://scala-blogs.org/2008/07/application-trait-considered-harmful.html
>>>
>>> -Mark
>>>
>>> On Tuesday 07 July 2009, turicum wrote:
>>>> object Test extends Application {
>>>>
>>>>     val s = future(getData("AAPL\n"))
>>>>     val t = getData("INTC\n")
>>>>     println(t) // that's fine
>>>>     println(s()) // hangs here
>>>>
>>>>
>>>>                   def getData(query: String): String = {
>>>>          query
>>>>      }
>>>> }
>>>
>>>
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/future-hangs-tp24383831p24383979.html
> Sent from the Scala - User mailing list archive at Nabble.com.
>
>

 « Return to Thread: future hangs