Browsing 7239 questions and answers with Jon Skeet

Is it possible to create a deadlock in C# if nothing but the lock keyword is used around primitive data access?

I've written a lot of multi-threaded C# code, and I've never had a deadlock in any code I've released. I use the following rules of thumb: I tend to use nothing but the lock...
Jon Skeet
people
quotationmark

Yes, it's easy to deadlock, without actually accessing any data: private readonly object lock1 = new object(); private readonly object lock2 = new object(); public void Method1() { lock(lock1) { Thread.Sleep(1000); ... more 7/2/2015 7:27:49 PM

people

Weird Behavior of ResultSet

hello mates hope you having a nice day, i have a really weird problem with getting data from Mysql database in Java , in the method here : ResultSet tableExistence; . . . ...
Jon Skeet
people
quotationmark

The ResultSet documentation states: The docs do say "For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once." So technically, it's somewhat... more 7/2/2015 7:25:25 PM

people

subclass not updating variable taken from base class

Why is my output not giving expected result i.e. 25? I know my question is silly but I am new in Java programming. the output is run: 5 0 0 BUILD SUCCESSFUL (total time: 0...
Jon Skeet
people
quotationmark

why output is not giving expected result i.e. 25 Because you have two different objects, each with an independent a field. You're setting the value to 5 in one object, but then calling multi() on the other object, so it's using the... more 7/2/2015 4:25:29 PM

people

How to test a delegate using Moq and NUnit

I have a factory class returning a delegate like below (GetDelegate method) public interface IFactory { Func<int, string> GetDelegate(bool isValid); } public class...
Jon Skeet
people
quotationmark

One way would be to mock the result of calling IService1.A and IService2.B, in exactly the same way as if you were calling them directly. You could then check that when you call the returned delegate, you get the expected answer (and that... more 7/2/2015 4:14:22 PM

people

Getting ArgumentOutOfRangeException in Lists

I am using List of Lists in my project. When i run program i get ArgumentOutOfRangeException. But there is no range specified in list. I declared list like this: public static...
Jon Skeet
people
quotationmark

But there is no range specified in list No, there's an index specified (as an argument), and that's what's out of range. Look at your code: list[0].Add("Hussam"); That's trying to use the first list in list - but is list is empty,... more 7/2/2015 2:41:16 PM

people

SimpleDateFormat try parse, avoid empty catch block

I implemented the following method that can be used to convert a String to an accepted format: public static Date parseDate(final String dateString, final String[]...
Jon Skeet
people
quotationmark

You can use the overload of parse which takes a ParsePosition: public static Date parseDate(final String dateString, final String[] acceptedFormats) { ParsePosition position = new ParsePosition(0); for (String format :... more 7/2/2015 2:39:14 PM

people

Xml serializing dynamic string to boolean

Below is an instance of a simple job scheduler which parses xml dynamic strings to json: XML <Navigations> <Navigation Name="facebook" Active ="0"...
Jon Skeet
people
quotationmark

Well yes, "0" isn't a valid value for a Boolean. It sounds like you possibly want something like: List<NavigationData> nds = new List<NavigationData>(); foreach (dynamic cnav in (IEnumerable)c.Navigations) { NavigationData... more 7/2/2015 8:14:46 AM

people

Sobel operator doesn't work with rectangle images

I try to implement Sobel operator in Java but the result is just some mix of pixels. int i, j; FileInputStream inFile = new FileInputStream(args[0]); BufferedImage...
Jon Skeet
people
quotationmark

Your code appears to expect Raster.getPixels to produce a result in columns, like this: 0 3 6 1 4 7 2 5 8 But I believe it actually does it in rows, like this: 0 1 2 3 4 5 6 7 8 So basically, where you currently have... more 7/2/2015 6:07:35 AM

people

How to extends Abstract Inner Class in java

I confused if Abstract Class A{method();method2();} And Other Class B Which Have Inner Class C Class B{Abstract Class C{method(){//body}}} And now Question is how to extends...
Jon Skeet
people
quotationmark

First, let's make it simpler - this has nothing to do with Android directly, and you don't need your A class at all. Here's what you want: class Outer { abstract class Inner { } } class Child extends Outer.Inner { } That... more 7/2/2015 5:53:34 AM

people

Getting different answer even after using Join() in threads C#

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Reflection; using...
Jon Skeet
people
quotationmark

You have three threads running concurrently, all mutating shared state in an unsafe way: The increment isn't atomic, in that it's "read, locally increment, write" - if multiple threads read the same value, then each locally increment,... more 7/1/2015 12:52:24 PM

people